关于map
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(){
map<string,int> simap;
string key,value;
while( cin >> key >> value){
simap.insert( make_pair(key, value) );//这条语句报错,我看了半天也没看出什么原因。
}
map<string,int>::iterator iter = simap.begin();
while(iter != simap.end()){
cout << iter->first << "\t\t"
<< iter->second << endl;
}
system("pause");
return 0;
}
报错:In constructor `std::pair<_T1, _T2>::pair(const std::pair<_U1, _U2>&) [with _U1 = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _U2 = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _T1 = const std::string, _T2 = int]':
什么原因啊,我实在是找不出原因来??谁能帮我看看!!
[解决办法]
map采用的是键-直来存储数据的,里面只有键是由你来定的,值不错允许私自更改的。
[解决办法]
- C/C++ code
string key,value; => string key;int value;
[解决办法]
value int型别。