-
STL Map
I am trying to get this map to to store cutomer names and referenced by a id number. I cannot figure out why i am getting 18 errors. I am confused. here is the code, thanks in advance for any help.
Code:
#include <iostream>
#include <map>
#include <string>
using namespace std;
void main (void)
{
typedef map<int, string, less<int>> C;
C customer;
customer.insert(C::value_type(5, "Dave"));
customer.insert(C::value_type(45, "Jon"));
cout<<"PIN Number"<<'\t'<<"Name"<<endl;
C::const_iterator i;
for(i=customer.begin(); i!=customer.end(); ++i)
cout<<i->first<<'\t'<<'\t'
<<i->second<<'\n';
}
-
Thanks to the wonderful world of C++ parsing, in typedef map<int, string, less<int>> C; the >> is a single token. Put a space between the greater than characters and everything should be fine: typedef map<int, string, less<int> > C;. And make sure you use int main(void). Not only is it the correct way, but it is one character less than void main(void).