Thread: String indexes.

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    21

    String indexes.

    When I got a string defined "string MyString" does this have a MyString[0] or does it start at MyString[1].

    Also is a string terminated with a "\0" or NULL character?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Crux
    When I got a string defined "string MyString" does this have a MyString[0] or does it start at MyString[1].
    Like arrays, std::string indices begin from 0.

    Quote Originally Posted by Crux
    Also is a string terminated with a "\0" or NULL character?
    std::string does not have the notion of a terminating character. If you use the c_str() member function, you would obtain a pointer to the first character of a string that is terminated by a null character, i.e., '\0'.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM