Dev-C++下问题

onejian 2010-07-24 05:16:18
"单词转换"
代码:
#include <iostream>

#include <stdexcept>

#include <fstream>

#include <sstream>

#include <string>

#include <map>

using namespace std;

ifstream& open_file (ifstream &in, const string &file);

int main(int argc, char **argv)

{

map<string, string> trans_map;

string key, value;

if (argc != 3) { throw runtime_error("wrong number of arguments"); }

ifstream map_file;

if (!open_file(map_file, argv[1])) { throw runtime_error("no transfromation file"); }

while (map_file >> key >> value)

{

trans_map.insert(make_pair(key, value));

}

ifstream input;

if (!open_file(input, argv[2])) { throw runtime_error("no input file"); }

string line;

while (getline(input, line))

{

istringstream stream(line);

string word;

while (stream >> word)

{

map<string , string>::const_iterator map_it = trans_map.find(word);

if (map_it != trans_map.end())

{

word = map_it->second;

}

cout << word << " ";

}

cout << endl;

}
system("pause");
return 0;

}

ifstream& open_file (ifstream &in, const string &file)

{

in.close();

in.clear();

in.open(file.c_str());

return in;

}



--replace.txt--

`en them

cuz because

gratz grateful

i I

nah no

pos supposed

sez said

tanx thanks

wuz was

--input.txt--

nah i sez tanx cuz i wuz pos to not cuz i wuz gratz

--屏幕输出--

main replace.txt input.txt

no I said thanks because I was supposed to not because I was grateful
为什么在dev c++下界面一闪而过。加了system("pause"),没用。帮忙下,怎么解决?谢谢
...全文
85 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
onejian 2010-07-24
  • 打赏
  • 举报
回复
在线求正解。
onejian 2010-07-24
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 cattycat 的回复:]
对,先按3楼的关闭文件流。
[/Quote]
呵呵,谢谢帮忙!
onejian 2010-07-24
  • 打赏
  • 举报
回复
按5楼方法,不行啊。谢谢帮忙
cattycat 2010-07-24
  • 打赏
  • 举报
回复
对不起,忽略我说的吧。
cattycat 2010-07-24
  • 打赏
  • 举报
回复
对,先按3楼的关闭文件流。
jixingzhong 2010-07-24
  • 打赏
  • 举报
回复
cin.sync();
system("pause");
cattycat 2010-07-24
  • 打赏
  • 举报
回复
加上#include <cstdlib>
不行的话试试getchar()吧。
jixingzhong 2010-07-24
  • 打赏
  • 举报
回复
system("pause");
前面先清空所有的输入流缓冲内容
onejian 2010-07-24
  • 打赏
  • 举报
回复
谢谢楼上,不是这问题!在线等
黑泡泡选手 2010-07-24
  • 打赏
  • 举报
回复

getch();

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧