Error while using std::string in Classes/Objects

This is a discussion on Error while using std::string in Classes/Objects within the Windows Programming forums, part of the Platform Specific Boards category; The idea is to store the player's name into a string. Here's the full source code... ps. I'm working this ...

  1. #1
    Registered User philvaira's Avatar
    Join Date
    Apr 2004
    Posts
    72

    Error while using std::string in Classes/Objects

    The idea is to store the player's name into a string. Here's the full source code...

    ps. I'm working this out in the console command before throwing this onto win32 api, so please tell me if it'll be compatable when I switch it over. Thanks.

    Code:
    #include <iostream>
    #include <string.h>
    
    class Common
    {
    public:
    	std::string getName() const { return Name; }
    	void setName(std::string a_name) { Name = a_name; }
    private:
    	std::string Name;
    };
    
    int main()
    {
    	using std::cout;
    	using std::cin;
    	using std::endl;
    
    	Common PC;
    	PC.setName("Aylen");
    
    	cout << PC.getName() << endl;
    
    	return 0;
    }

    Bug:
    Code:
    error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::alloc

  2. #2
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Strange, compiles fine for me on MingW/Dev-C++ 4.9.8.0.

    What compiler are you using?

  3. #3
    Registered User philvaira's Avatar
    Join Date
    Apr 2004
    Posts
    72
    I'm using VC++ 6.0 Pro...

  4. #4
    Registered User philvaira's Avatar
    Join Date
    Apr 2004
    Posts
    72
    WOO HOO!

    I put #include <string> instead of <string.h> lol

    It's always the little things.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 12-14-2007, 03:34 PM
  2. Improving my code
    By rwmarsh in forum C++ Programming
    Replies: 14
    Last Post: 07-08-2006, 12:18 PM
  3. Debugging help
    By cuddlez.ini in forum C++ Programming
    Replies: 3
    Last Post: 10-24-2004, 08:08 PM
  4. DLL and std::string woes!
    By Magos in forum C++ Programming
    Replies: 7
    Last Post: 09-08-2004, 01:34 PM
  5. returning std::string
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 09-24-2001, 09:31 PM

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