Thread: Question about std::string..

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Code:
    #include <iostream>
    
    int main()
    {
    	std::string str("Hello, world!");
    	
    	std::cout << str << std::endl;
    	
    	return 0;
    }
    If this compiles and runs, you have a different problem. Make sure you're including iostream and possibly the string header string.

  2. #2
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    Code:
    #include <string.h>
    #include <iostream>
    
    class TextEngine
    {
    	void Respond()
    	{
    		std::cout << Response << std::endl;
    	}
    	std::string Response;
    
    };
    Thats the whole thing, and it doesn't work.... I wonder...
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    All of the class members are private, so calling Respond() outside of other class member functions is impossible. Might I add that MacGuyver has the simplest idea with the least boilerplate code.

  4. #4
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    I forgot about string and string.h

    Ooops! :d
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  5. #5
    Registered User
    Join Date
    May 2007
    Posts
    13
    Quote Originally Posted by Shamino View Post
    I forgot about string and string.h

    Ooops! :d
    I guess that's why your the Absent minded programmer

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging help
    By cuddlez.ini in forum C++ Programming
    Replies: 3
    Last Post: 10-24-2004, 07:08 PM
  3. DLL and std::string woes!
    By Magos in forum C++ Programming
    Replies: 7
    Last Post: 09-08-2004, 12:34 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. returning std::string
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 09-24-2001, 08:31 PM