第三章字符串 向量 数组
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
没有截止符引发的越界读写。