64,282
社区成员
发帖
与我相关
我的任务
分享
#include "targetver.h"
#include <iostream>
#include <stdio.h>
#include <tchar.h>
#include <map>
#include <string>
#include<fstream>//文件输入输出的流类
#include <sstream>
using namespace std;
ifstream& open_file(ifstream &in,const string &file)
{
in.close();
in.clear();
in.open(file.c_str());
return in;
}
int _tmain(int argc, _TCHAR* argv[])
{
map<string,string> trans_map;
string key,value;
if (argc!=3)
{
throw runtime_error("wrong number of arguments");//debug error
}
ifstream map_file;
if (!open_file(map_file,argv[1])) //debug assertion failed
{
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;
}
if (!open_file(map_file,file)) //debug assertion failed
{
throw runtime_error("no transformation file");//在这一句
}
if (!open_file(map_file,file)) //debug assertion failed
{
throw runtime_error("no transformation file");
}
这一句就卡了 0x7607812f 处未处理的异常: Microsoft C++ 异常: 内存位置 0x0030f434 处的 std::runtime_error。
'en them
cuz because
gratz grateful
i r
nah no
pos supposed
sez said
tanx thanks
wuz was
文本文件里面的内容 通过前面的找到后面的如 输入sez出来的是said
#include <iostream>
#include <stdio.h>
#include <tchar.h>
#include <map>
#include <string>
#include<fstream>//文件输入输出的流类
#include <sstream>
using namespace std;
ifstream& open_file(ifstream &in,const string &file)
{
in.close();
in.clear();
in.open(file.c_str());
return in;
}
int main()
{
map<string,string> trans_map;
string key,value;
/*if (argc!=3)
{
throw runtime_error("wrong number of arguments");//debug error
}*/
string file = "1.txt"; //文件里面存:
//Chinese 中文
//English 英文
//Japanese 日文
ifstream map_file;
if (!open_file(map_file,file)) //debug assertion failed
{
throw runtime_error("no transformation file");
}
while(map_file>>key>>value)
trans_map.insert(make_pair(key,value));
ifstream input;
string fil = "2.txt"; //文件里面存:
//Chinese
//English
//Japanese
if (!open_file(input,fil))
{
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;
}
system("pause");
return 0;
}
#include <iostream>
#include <stdio.h>
#include <tchar.h>
#include <map>
#include <string>
#include<fstream>//文件输入输出的流类
#include <sstream>
using namespace std;
ifstream& open_file(ifstream &in,const string &file)
{
in.close();
in.clear();
in.open(file.c_str());
return in;
}
int main()
{
map<string,string> trans_map;
string key,value;
/*if (argc!=3)
{
throw runtime_error("wrong number of arguments");//debug error
}*/
string file = "1.txt"; //文件里面存Chinese 中文
English 英文
Japanese 日文
ifstream map_file;
if (!open_file(map_file,file)) //debug assertion failed
{
throw runtime_error("no transformation file");
}
while(map_file>>key>>value)
trans_map.insert(make_pair(key,value));
ifstream input;
string fil = "2.txt"; //文件名
if (!open_file(input,fil))
{
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;
}
system("pause");
return 0;
}
#include <iostream>
#include <stdio.h>
#include <tchar.h>
#include <map>
#include <string>
#include<fstream>//文件输入输出的流类
#include <sstream>
using namespace std;
ifstream& open_file(ifstream &in,const string &file)
{
in.close();
in.clear();
in.open(file.c_str());
return in;
}
int main()
{
map<string,string> trans_map;
string key,value;
/*if (argc!=3)
{
throw runtime_error("wrong number of arguments");//debug error
}*/
string file = "xxxxxx"; //文件名
ifstream map_file;
if (!open_file(map_file,file)) //debug assertion failed
{
throw runtime_error("no transformation file");
}
while(map_file>>key>>value)
trans_map.insert(make_pair(key,value));
ifstream input;
string fil = "xxxxxxx"; //文件名
if (!open_file(input,fil))
{
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;
}
system("pause");
return 0;
}
楼主可以参考下