Thread: variable type string

  1. #1
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    variable type string

    What is the header I need to declare a string? Not an array or char, but a string. I tried <string>, <string.h>, but I still get an error when trying to do something like:

    string message;

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    <cstring>

    edit: nevermind, errors still show up for this also.
    Last edited by alpha; 01-26-2003 at 01:59 PM.

  3. #3
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    The correct header for the string class is <string>, but if you don't handle namespaces anywhere you'll get errors, so you need to do one of these.
    Code:
    #include <string>
    
    using namespace std;
    
    ...
    string message;
    Code:
    #include <string>
    
    using std::string;
    
    ...
    string message;
    Code:
    #include <string>
    
    ...
    std::string message;
    *Cela*

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    yeah, i forgot the std stuff. i didn't know if you don't do using namespace std; or using std::string; that you need to do std::string for declaration. just tried it, no errors.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM
  5. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM