- #include <iostream>
-
-
#include <string.h>
-
-
using namespace std;
-
-
-
-
int main()
-
-
{
-
-
char val[15] = {'c', 'e', 'o', 'd', 'e'};
-
-
for(int i = 0; i < 15; i++)
-
-
cout << (int)val[i] << " "; //val[5] ~ val[14] 都为NULL
-
-
cout << endl;
-
-
cout << val << endl;
-
-
cout << "sizeof(val) = " << sizeof(val) << endl;
-
-
-
-
string str = val; // 将val数组中第一个NULL元素之前的字符放到str字符串中
-
-
cout << str << endl;
-
-
cout << "str.size = " << str.size() << endl;
-
-
return 0;
-
-
}
output:
99 101 111 100 101 0 0 0 0 0 0 0 0 0 0
ceode
sizeof(val) = 15
ceode
str.size = 5
阅读(712) | 评论(0) | 转发(0) |