C++ Primer上的一个例题,运行出错解决办法

C++ Primer上的一个例题,运行出错
就是第十章A Word Transformation Map那一节的例题,照着打的,编译也通过了,但是运行出错了,弹出个对话框,也没给出有用的信息。目标很简单,具体到我这个程序,就是我有两个文档,
第一个叫做Transform,里面的内容如下:
'em them
cuz because
gratz grateful
i I
nah no
pos supposed
sez said
tanx thanks
wuz was

左边一列是原来的单词,右边的是要被转换成的单词。

第二个叫做original_text,里面就是一段文字,比如说是
nah i sez tanx cuz i wuz pos to
not cuz i wuz gratz

这个程序的目的就是将第一个文档中的数据读入一个map里面,然后再读入第二个文档,对第二个文档中的每个单词在map中进行搜索,看看需不需要替换。最后将转换后的文档内容在控制台输出。


有木有大神看出来问题出在哪儿的吗?表示C++关于文档的操作很纠结啊!


/*
A program to transform words.
Takes two arguments: The first is the name of the word transformation file
 The second is the name of the input to transform
*/

#include <iostream>
#include <utility>
#include <string>
#include <map>
#include <fstream>
#include <sstream>

using std::istringstream;
using std::ifstream;
using std::ostream;
using std::string;
using std::pair;
using std::map;
using std::cin;
using std::cout;
using std::endl;
using std::runtime_error;
using std::cerr;

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

int main(int argc, char **argv)
{
// map to hold the word transformation pairs:
// key is the word to look for in the input; value is the word to use in the output
map<string, string> trans_map;
string key, value;
if(argc != 3)
throw runtime_error("wrong number of arguments");

// open transformation file and check that open succeeded
ifstream map_file;
open_file(map_file, "Transform.txt");
if(!open_file(map_file, "Transform.txt"))
throw runtime_error("no transformation file");

// read the transformation map and build the map
while(map_file>>key>>value)
trans_map.insert(make_pair(key, value));
//OK, now we're ready to do the transformations
// open the input file and check that the open succeeded
ifstream input;
open_file(input,"original_text.txt");
if(!open_file(input,"original_text.txt"))
throw runtime_error("no input file");

string line;   // hold each line from the input
// read the text to transform it one line at a time
while(getline(input, line))
{
istringstream stream(line);  // read the line one word at a time
string word;
bool firstword = true;  // controls whether a space is printed
while(stream >> word)
{
// OK: the actual mapwork, this part is the part of the program
map<string, string>::const_iterator map_it=trans_map.find(word);
// if this word is in the transformation map
if(map_it!=trans_map.end())
// replace it by the transformation value in the map
word = map_it->second;
if(firstword)
firstword = false;
else
cout<<" ";  // print space between words
cout<<word;
}
cout<<endl;  // done with this line of input
}

}


ifstream& open_file(ifstream &in,const string &file)
{
 in.close();
 in.clear();
 in.open(file.c_str());
 return in;
}

文档 map

------解决方案--------------------
参数在VS的项目属性里
C++ Primer上的一个例题,运行出错解决办法
------解决方案--------------------
引用:
经过仔细的搜索,跨过了预言的障碍,我终于找到你的那个对话框了!不过这也太纠结了吧!有木有更加直观的编程方式?

不懂argc,argv?...这个就是程序的输入参数,argc是参数的个数,然后argv是指定的参数名称。
你dos命令知道吧,比如ping 127.0.0.1,ping就是这个程序,然后127.0.0.1就是那个你指定的参数。
所以你的程序(名称假设为test)在命令行中调用就是(先切换到相应的目录下),然后输入这个命令就可以了
test Transform.txt original_text.txt
argv[0]是程序的地址,argv[1]就是第一参数Transform.txt,以此类推