#include<iostream>
using namespace std;
int main()
{
char test[10];
char cont[10];
cin.getline(test,10);
cin.getline(cont,10);
cout<<test<<" is not "<<cont<<endl;
return 0;
}
当我输入:
输出结果为:12345678901234567890
看起来123456789
cont
是空的。有人可以解释一下吗?(说明:此处的“cont”是指代码中的变量名称,未提供更多上下文信息)
cin.getline
的存在,改用std::getline
。虽然std::getline
也不是完美的,但在绝大多数情况下,它肯定会有所提升。 - Jerry Coffin