#include #include using namespace std; int main() { // 字符串打印遇到\0则结束打印 string str1 = "abc\0good"; // abc\0good\0 cout << str1 << str1 << endl; cout << "sizeof str1 = " << sizeof(str1) << endl; // 32B 32*8=256位 char str2[] = "disen666"; // 字符数组, 实际上也是一个字符串 cout << "str2 = " << str2 << endl; char str3[] = {'d', 'i', 's', 'e', 'n'}; // 自动添加 '\0' cout << "str3 = " << str3 << endl; cout << "sizeof str3 = " << sizeof(str3) << endl; // 5B, 没算 '\0' string str4 = "a"; cout << "sizeof str4 = " << sizeof(str4) << endl; // 32B 32*8=256位 return 0; }