vc++2010xp 为什么注释除必须加<<endl;才能将word完整输出?

C++语言 码拜 9年前 (2015-05-11) 897次浏览 0个评论

std::map<string, string> buildMap(ifstream &map_file)
{
    std::map<string, string> trans_map;
    for (string key, value; map_file >> key && getline(map_file, value); )
        if (value.size() > 1) trans_map[key] = value.substr(1).substr(0, value.find_last_not_of(“” “”));
    return trans_map;
}
const string & transform(const string &s, const std::map<string, string> &m)
{
    auto map_it = m.find(s);
    return map_it == m.cend() ? s : map_it->second;
}
void word_transform(ifstream &map, ifstream &input)
{
    auto trans_map = buildMap(map);
    for (string text; getline(input, text); ) {
        std::istringstream iss(text);
        for (string word; iss >> word; )
            std::cout << transform(word, trans_map) <<endl;    //此处必须加上endl,可能是因为版本问题或是电脑问题
        std::cout << std::endl;
    }
}

20分
不是,因为cout是带输出缓冲的,当输出缓冲区达到一定大小或程序到达结尾或者遇到cout<<endl,就会对缓冲区中的内容进行输出
原来是输入时的map文件出错了“\r\n”;
20分
不想加<<std::endl;你也可以加;std::cout.flush();
嗯,我的格式错了,各位的都可以刷新缓冲区

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明vc++2010xp 为什么注释除必须加<<endl;才能将word完整输出?
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!