还是关于getline()
由于对getline()函数一直不解,在论坛里找了个关于getline()例子 稍微改了改 结果又出问题了 #include<iostream>
using namespace std;
int main()
{
char mystr[100];
int n,i;
cin>>n;
for(i=0;i<n;i++)
{
cout<<"what's your name? ";
cin.getline(mystr,100);
cout<<"Hello "<<mystr<<".\n";
cout<<"what is your favorite color? ";
cin.getline(mystr,100);
cout<<"I like "<<mystr<<" too!\n";
}
return 0;
}
例如:
先输入1付给n;
然后它就直接输出:
what's your name?
what is your favorite color?
这两句连着输出了 为什么呀?