C++vector< <pair<string,int> >数据怎么读取?
pair<string,int>psi;vector<pair<string,int>>str_int;stringstr;intinteger;cout<<"pleas...
pair<string,int> psi;
vector< pair<string,int> > str_int;
string str;
int integer;
cout << "please enter charater and integer(ctrl+z to end:)" << endl;
while( cin >> str >> integer ){
psi = make_pair(str,integer);
str_int.push_back(psi);
}
vector< pair<string,int> >::iterator read;
read = str_int.begin();
while( read != str_int.end() ){
cout << *read.first++ << endl;//我想在这里读取vector里的pair类型数据,可编译错误!请问我该怎么样读取?
}
return 0; 展开
vector< pair<string,int> > str_int;
string str;
int integer;
cout << "please enter charater and integer(ctrl+z to end:)" << endl;
while( cin >> str >> integer ){
psi = make_pair(str,integer);
str_int.push_back(psi);
}
vector< pair<string,int> >::iterator read;
read = str_int.begin();
while( read != str_int.end() ){
cout << *read.first++ << endl;//我想在这里读取vector里的pair类型数据,可编译错误!请问我该怎么样读取?
}
return 0; 展开
2个回答
推荐于2016-02-09 · 知道合伙人数码行家
关注
展开全部
代码如下,亲测可用:
pair<string,int> psi; vector< pair<string,int> > str_int; string str; int integer; cout << "please enter charater and integer(ctrl+z to end:)" << endl; while( cin >> str >> integer ){ psi = make_pair(str,integer); str_int.push_back(psi); } vector< pair<string,int> >::iterator read; read = str_int.begin();
while( read != str_int.end() )
{
cout << (*read).first << endl;
read++;
}} return 0;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询