STL Map

This is a discussion on STL Map within the C++ Programming forums, part of the General Programming Boards category; I am trying to get this map to to store cutomer names and referenced by a id number. I cannot ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    5

    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';
    
    	
    }

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    101
    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).
    - lmov

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  2. Problem with static STL i.e. map
    By vijay_choudhari in forum C++ Programming
    Replies: 2
    Last Post: 10-26-2007, 05:56 AM
  3. STL Map Object
    By nomes in forum C++ Programming
    Replies: 6
    Last Post: 09-11-2003, 01:51 PM
  4. Unsorted Map and Multimap :: STL
    By kuphryn in forum C++ Programming
    Replies: 5
    Last Post: 12-21-2002, 10:22 PM
  5. Searching STL Map Inside STL Map Object :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 11-14-2002, 08:11 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21