第三章字符串 向量 數組
string 初始化
初始化類型:拷貝初始化、直接初始化
使用=初始化即爲,拷貝初始化。
char 數組與string
char 數組如果沒有\0截止符 將引發讀寫越界的問題
string 可以會在初始化的時候自動加入截止符
#include "a.hpp"
#include<iostream>
using std::string;
using std::cout;
using std::endl;
int main()
{
const char ca[] = {'h','e','l','l','o'};
string str("liu chuan wu");
const char *p = ca;
while(*p)
{
cout<<*p;
++p;
}
cout<<endl;
}
輸出結果:helloliu chuan wu
沒有截止符引發的越界讀寫。