Thread: Error while using std::string in Classes/Objects

  1. #1
    Registered User
    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
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    Strange, compiles fine for me on MingW/Dev-C++ 4.9.8.0.

    What compiler are you using?

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

  4. #4
    Registered User
    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, 11:18 AM
  3. Debugging help
    By cuddlez.ini in forum C++ Programming
    Replies: 3
    Last Post: 10-24-2004, 07:08 PM
  4. DLL and std::string woes!
    By Magos in forum C++ Programming
    Replies: 7
    Last Post: 09-08-2004, 12:34 PM
  5. returning std::string
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 09-24-2001, 08:31 PM