一个C++ while循环的问题,为什么测试条件可以是cin>>之类的语句
#include<iostream>#include<cstring>intmain(){usingnamespacestd;intcount=0;charar[20];...
#include <iostream>
#include <cstring>
int main()
{
using namespace std;
int count = 0;
char ar[20];
char arm[] = "done";
cout << "Enter words (to stop, type the word done): " << endl;
while (cin >> ar && strcmp(ar, arm))
++count;
cout << "You entered a total of " << count << " words" << endl;
return 0;
}
cin>>ar 是将字符读取到数组,不包括空格啊换行的,为什么它这里能一次只将一个单词读到数组,它是读到空格就自动停止读取了吗? 展开
#include <cstring>
int main()
{
using namespace std;
int count = 0;
char ar[20];
char arm[] = "done";
cout << "Enter words (to stop, type the word done): " << endl;
while (cin >> ar && strcmp(ar, arm))
++count;
cout << "You entered a total of " << count << " words" << endl;
return 0;
}
cin>>ar 是将字符读取到数组,不包括空格啊换行的,为什么它这里能一次只将一个单词读到数组,它是读到空格就自动停止读取了吗? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询