CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2010
    Posts
    60

    Could someone please explain "String" to me?

    Im new to C++.. Wondering what "string" is and what its used for?

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Could someone please explain "String" to me?

    A string is a type which holds any sequence of characters, typically a word or sentence. std::string is a robust implementation of the concept in the C++ standard library.

  3. #3
    Join Date
    Aug 2008
    Posts
    902

    Re: Could someone please explain "String" to me?

    Quote Originally Posted by UpcomingChris View Post
    Im new to C++.. Wondering what "string" is and what its used for?
    In general, a string is a line of text. Example: "This is a string"

    In C, there are no strings. Instead, you use an array of individual characters. The last value in the array is always 0 (null) which marks the end of the string. Example:

    char[] name = "Chris";

    which is actually an array of type char: 'C', 'h', 'r', 'i', 's', '\0'

    In C++, a new typedef is added called std::string, which is actually a template class (basic_string<T>) being called as basic_string<char>.

    It's basically a template that wraps your normal character array and gives you an easier interface to work with.

    To use a string in a function that reacquires a char[] all you have to do is:

    void printname(const char* name);

    string name = "Chris";
    printname( name.c_str() );

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Could someone please explain "String" to me?

    Despite that you will find tons of resources using your favorite search engine....Wikipedia is your friend: string (C++)...

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

Featured