simple map<string,float> not working

This is a discussion on simple map<string,float> not working within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> #include <map> using namespace std; int main() { map<string, float> name_weight; name_weight["manav"] = 62.5f; name_weight["khushi"] = 67.5f; ...

  1. #1
    Banned
    Join Date
    Nov 2007
    Posts
    678

    simple map<string,float> not working

    Code:
    #include <iostream>
    #include <map>
    using namespace std;
    
    int main()
    {
    	map<string, float> name_weight;
    
    	name_weight["manav"] = 62.5f;
    	name_weight["khushi"] = 67.5f;
    
    	for(map<string, float>::iterator it = name_weight.begin(); it != name_weight.end(); ++it)
    	{
    		cout << it->first << " weighs " << it->second << "Kg" << endl;
    	}
    
    	return 0;
    }
    This simple map example gives me the following error under MSVS .Net 2003:
    test4.cpp(14) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const std::string' (or there is no acceptable conversion)

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,295
    I think you need to include <string>
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Add this:
    Code:
    #include <string>

  4. #4
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Thanks!
    I think I am depending too much on compilers error reporting!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [PAID] Very simple C script - Not working?
    By spadez in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 02-12-2009, 07:00 AM
  2. Simple program not working, don't know why
    By Bakster in forum C Programming
    Replies: 11
    Last Post: 01-29-2009, 12:56 PM
  3. Replies: 3
    Last Post: 09-12-2005, 09:08 AM
  4. Replies: 5
    Last Post: 02-02-2003, 09:56 AM
  5. simple program not working
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 03-04-2002, 10:36 PM

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