23 lines
423 B
C++
23 lines
423 B
C++
|
// 按字符串读取,读取到第一`\0`结束。
|
||
|
#include <iostream>
|
||
|
#include <cstdlib>
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
char arr[] = "hello";
|
||
|
cout << sizeof(arr) << endl; // 6B
|
||
|
|
||
|
// 逐个读取
|
||
|
int i = 0;
|
||
|
while (arr[i]) // arr[i] != '\0', 因为 '\0' 的 ASCII 码为 0
|
||
|
{
|
||
|
cout << arr[i++] << endl;
|
||
|
}
|
||
|
cout << endl;
|
||
|
|
||
|
// 一次读取
|
||
|
cout << arr << endl;
|
||
|
return 0;
|
||
|
}
|