Strings in C++?

This is a discussion on Strings in C++? within the C++ Programming forums, part of the General Programming Boards category; Hi Everyone, I'm new here, so please don't be so harsh on me hehe. So basically, I went out and ...

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    18

    Question Strings in C++?

    Hi Everyone,
    I'm new here, so please don't be so harsh on me hehe.

    So basically, I went out and purchased "C++ For Dummies, 5th Edition", and read the variables section. It says for strings, you use it in the following format:

    Code:
    string szMyString;
    However, when I put this in, I get a compiler error. I don't think string is recognised as a variable type because it doesn't get highlighted.

    So I was wondering, what's going on? Does C++ even support strings? Is there some sort of different header apart from the iostream I need to include?

    Oh, happy new year everyone, hope you've all had an excellent Christmas.

    Thanks .

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,272
    You need to #include <string>. Also, unless you have a using directive like using namespace std; or a using declaration like using std::string;, you should fully qualify the name as std::string.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2008
    Posts
    18
    Quote Originally Posted by laserlight View Post
    You need to #include <string>. Also, unless you have a using directive like using namespace std; or a using declaration like using std::string;, you should fully qualify the name as std::string.
    Thanks a lot!
    Have an excellent new year.

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    137
    The cool thing about strings are that you can even access individual characters like char string arrays, like so: szString[i];

    If you need to convert to char array: szString.c_str();
    And if you need to cut up sections, use .substr()!

    good luck!
    ★ Inferno provides Programming Tutorials in a variety of languages. Join our Programming Forums. ★

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    That's not cool, that's the biggest headache in trying to produce a std::string-compliant proper unicode-based string implementation.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User
    Join Date
    Dec 2008
    Posts
    18
    Nice Thanks guys.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 03:24 PM
  2. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 08:07 PM
  3. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 07:37 AM
  4. damn strings
    By jmzl666 in forum C Programming
    Replies: 10
    Last Post: 06-24-2002, 03:09 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 12:23 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21