Thread: Newbie Question: Can't use #include <string>

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    5

    Newbie Question: Can't use #include <string>

    Hello,

    I am trying to define a variable of type string, however the compiler does not like it.

    I've done #include <string>.

    I'm using the Bloodshed compiler. The include files are there. Please help.

  2. #2
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Try adding this line after the includes:

    Code:
    using namespace stl;

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    5
    Thanks for the quick reply. That did not work however. It did not like that line of code. Also, I already had the line:

    Code:
    using namespace std;

  4. #4
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    Could you post the code with the errors you got? That'll make it easier for us to help you out.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    5
    Here it's just a simple test trying to get the string to work.

    Code:
    #include <iostream>
    #include <string>
    
    int main()
    {
        string test;
        
        return 0;
    }
    Error: 'string' undeclared

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    What version of Dev-Cpp are you using? I don't think they updated to the new C++ standard until the 5.0 beta.

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    5
    I'm using 4.9.9.1

    I just downloaded it from their website. It was the most recent one.

  8. #8
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    Code:
    #include <iostream>
    #include <string>
    
    int main()
    {
        std :: string test;
        
        return 0;
    }
    You need to declare the namespace you're using by adding std:: before the type declaration.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie function return question
    By faifas in forum C Programming
    Replies: 2
    Last Post: 06-29-2009, 10:19 AM
  2. A newbie question...i think..
    By AbeMazur in forum C++ Programming
    Replies: 3
    Last Post: 02-24-2009, 12:34 PM
  3. 2d game
    By JordanCason in forum Game Programming
    Replies: 5
    Last Post: 12-08-2007, 10:08 PM
  4. MFC include BS
    By VirtualAce in forum Windows Programming
    Replies: 4
    Last Post: 10-31-2005, 12:44 PM
  5. newbie question
    By invisibleghost in forum C Programming
    Replies: 5
    Last Post: 08-23-2005, 12:56 AM