请求帮忙:C++中的回车

来源:百度知道 编辑:UC知道 时间:2024/06/21 23:24:42
//C++
int i=0;
char message[100];
while(i<100)
{
cin>>message[i];
if(message[i]=='\n')
break;
i++;
}
当我输入一串字符后再输入回车去不能推出while循环,知道输入99个字符为止,为什么?

在输入时,cin以回车作为一个输入的结束,因此不会把\n保存到数组中,你用其他的字符作为结束条件。

干嘛搞这么麻烦, 直接整串输入不就行了
#include <iostream>
using namespace std;

int main()
{
char messege[100];
cin>>messege;
return 0;
}