+ -
当前位置:首页 → 问答吧 → vs2010 如何在工程的同一目录下添加了2个文件

vs2010 如何在工程的同一目录下添加了2个文件

时间:2011-12-15

来源:互联网

我是在看c++ primer 上的一个代码 但是不知道如何在代码中导入argv[1]和argv[2]这两个文件 (我用的是vs2010)
这是源代码:
#include<iostream>
#include<fstream>
#include<sstream>
#include<map>
#include<utility>
#include<stdexcept>
#include<string>
using namespace std;
ifstream& open_file(ifstream &in,const string &file)
{
in.close();
in.clear();
in.open(file.c_str());
return in;
}
int main(int argc,char **argv)
{
map<string,string>trans_map;
string key,value;
if(argc!=3)
throw runtime_error("错误的实参个数");
ifstream map_file;
if(!open_file(map_file,argv[1]))
throw runtime_error("没有转换文件");
while(map_file>>key>>value){
trans_map.insert(make_pair(key,value));
}
ifstream input;
if(!open_file(input,argv[2]))
throw runtime_error("没有输入文件");
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;
}
我是一个新手 请各位多多指教啊 在下感激不尽啊

作者: woshixinshoua_009   发布时间: 2011-12-15

比如这段代码编译链接生成的exe文件为c:\mydir\debug\test.exe
在cmd窗口里面输入以下命令
cd /d c:\mydir\debug
test in.txt out.txt

作者: zhao4zhong1   发布时间: 2011-12-15

热门下载

更多