首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于geiline函数,迷惑

2013-04-20 
关于geiline函数,不解为何代码中红色getline函数没有执行,很不解,求解释#include iostream#include map

关于geiline函数,不解
为何代码中红色getline函数没有执行,很不解,求解释

#include <iostream>
#include <map>
#include <cstdlib>
#include <string>
#include <vector>
#include <sstream>
using namespace::std;


int main()
{
int T, M, N;
string word1, word2, word;
string input_words;
vector<string> input_vec;
map<string, string> trans_map;

cout << "输入测试组数T" << endl;
cin >> T;
for (int i = 0; i < T; i++)
{
cout << "输入游戏者的数量N和单词转化列表长度M" << endl;
cin >> N >> M;
cout << "输入单词转化列表(单词之间以空格分隔)" << endl;
for (int j = 0; j < M; j++)
{
cin >> word1 >> word2;
cin.clear();
trans_map.insert(map<string, string>::value_type(word1, word2));
}
cout << "输入测试语句input" << endl;
getline(cin, input_words);
cout << input_words << endl;
istringstream stream(input_words);
while (stream >> word)
{
input_vec.push_back(word);
}

}


for (int k = 0; k != input_vec.size(); k++)
{
cout << input_vec[k] << endl;
}

/*map<string, string>::const_iterator it = trans_map.begin();
while (it != trans_map.end())
{
cout << it->first << " " << it->second << endl;
++it;
}
*/

return EXIT_SUCCESS;
}
[解决办法]
在getline函数上面加一个,cin.ignore();

热点排行
Bad Request.