Results 1 to 4 of 4

Thread: [C++] String class...Can't find it

  1. #1

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    [C++] String class...Can't find it

    I've tried everything to get a string working. I can't seem to find ANY helpful information on the compiler or classes you can use.

    I've tried the following:

    #include <string>
    #include <string.h>
    #include <String>
    #include <String.h>


    None of those work when I try to declare a String:

    String s;

    It gives me an error saying String is undeclared.
    I'm using the Bloodshed IDE by the way, and I looked at an example it came with and they used:

    #include <string.h>

    but that still doesn't work for me.

    Am I doing something wrong? Is there any helpful documentation?

  2. #2
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771

    Re: [C++] String class...Can't find it

    The C++ string class lives in the std namespace, you can use it with:
    Code:
    #include <string>
    std::string my_string = "this is a string";
    or:
    Code:
    #include <string>
    using namespace std;
    string my_string = "this is a string";

  3. #3

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: [C++] String class...Can't find it

    Thanks! That worked perfectly. I commented out using namespace std, so that was part of the reason I couldn't get it to work.

    One more thing if you don't mind. I've got a really old book that I like to read(it's called Mastering C++ for pascal and c programmers), and it was using a capital S for string. Has this changed in the newer version of C++?

  4. #4
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771

    Re: [C++] String class...Can't find it

    There never was a (standard) String class with a capital S. Maybe that book uses its own string class, or a speficic library.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width