菜鸟求教!!!!关于getline使用
本人大菜鸟,问个问题
想输入一系列词组,之间用回车隔开,将词组存入string数组里 怎么搞啊
string pswords[100];//定义一个string数组,将输入的词组储存在其中
int index=0;
while(getline(in,pswords[index])){
index++;
}
我的代码 不对。。。。。
求指导啊
[解决办法]
#include <iostream>#include <string>using namespace std;void main(){string pswords[100];//定义一个string数组,将输入的词组储存在其中int index=0;while(getline(cin,pswords[index]))//这里应该是cin{ if (pswords[index]=="0")//判断字符串结束 { break; } index++;}}
[解决办法]
#include <iostream>#include <string>using namespace std;void main(){ const int iLen = 100; string pswords[iLen];//定义一个string数组,将输入的词组储存在其中 int index=0; while(getline(cin,pswords[index]))//这里应该是cin { if(index++ == iLen - 1) break; } for (int i = 0; i< iLen ;i++) cout << pswords[i] << endl;}
[解决办法]