#include<iostream>
using namespace std;
int main()
{
char arr[200];
while(1) {
cin >> arr;
int i = sizeof(arr);
cout << "The arr input is "<< arr
<< " and the size of the array is "<< i << endl;
}
return 0;
}
对于34输入, 该代码输出:ARR的输入是34和阵列的大小是200如何获得数组中已用空间的大小? (NOT sizeof); C++
而我希望它得到的已用空间的大小阵列。因此,对于最后输入我希望它输出:ARR的输入是34和数组的大小是2
谁能告诉我怎么样?
注意,你的代码会爆炸,如果有人进入超过199个字符。另一个在C++代码中使用'std :: string'优先于旧式C-string的原因。 – 2010-02-10 00:18:11