c++prime 练习 11.12

来源:互联网 发布:编程语言难易排名 编辑:程序博客网 时间:2024/06/05 15:26
/*编写程序,读入string和int序列,将每个string和int存入一个pair中,pair保存在一个vector中。*/#include<iostream>#include<string>#include<fstream>#include<vector>#include<utility>int main(int argc,char *argv[]){using namespace std;ifstream in1(argv[1]),in2(argv[2]);if(!in1){cout<<"Can't open the file: "<<argv[1];exit(1);}if(!in2){cout<<"Can't open the file: "<<argv[2];exit(1);}vector<pair<string,int>> v1;string str_temp;intint_temp;while(in1>>str_temp&&in2>>int_temp){v1.push_back(make_pair(str_temp,int_temp));}for(const auto &p:v1){cout<<p.first<<' '<<p.second<<endl;}system("pause");}

0 0
原创粉丝点击