注册 登录
编程论坛 C++教室

程序运行出问题,帮忙解决下啊

morose2004 发布于 2011-07-10 18:31, 1264 次点击
我把书上的程序打了一遍想运行下看有什么结果,编译链接时都没有错误就是在运行时,系统“嘣”的响了一声,弹了个框,debug error:Debug Error!

Program: C:.......hahaha.exe

R6010

-abort() has been called

 

Press Retry to debug the application...

程序肯定没有问题我照书上抄的,我也没有打错,不过我还是把程序贴出来吧,感觉应该和程序没有关系
#include<iostream>
#include<fstream>
#include<sstream>
#include<list>
#include<string>
#include<vector>
#include<utility>
#include<map>
using namespace std;
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;
 ifstream& open_file(ifstream& in,const string &file);
 if(!open_file(map_file,argv[1]))
 {
 throw runtime_error("no transformation 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;
 bool firstword=true;
 while(stream>>word)
 {
 map<string,string>::const_iterator map_it=trans_map.find(word);
 if(map_it!=trans_map.end())
 word=map_it->second;
 if(firstword)
 firstword=false;
 else
 cout<<" ";
 cout<<word;
 }
 cout<<endl;
 }
 return 0;
}
ifstream& open_file(ifstream& in,const string &file)
{
 in.close();
 in.clear();
 in.open(file.c_str());
 return in;
}
3 回复
#2
杰仔19972011-07-10 21:15
路过
#3
lai03012011-07-11 02:43
在project菜单里设置工作目录 跟程序变量,如你要读取的文件在F盘,在工作目录写F:\,程序变量写你读取的文件名,例如你的文件名叫1.txt和2.txt则在程序变量一栏写1.txt 2.txt(文件名中间用空格)如果你程序保存位置跟读取文件位置在同一目录,则工作目录可以省略,只设置程序变量即可!
#4
lai03012011-07-11 02:46
protect 菜单点设置然后点Debug,嘿嘿。。。。
1