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;
}
我是一个新手 请各位多多指教啊 在下感激不尽啊
这是源代码:
#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
在cmd窗口里面输入以下命令
cd /d c:\mydir\debug
test in.txt out.txt
作者: zhao4zhong1 发布时间: 2011-12-15
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28