-
April 11th, 2010, 04:51 PM
#1
Could someone please explain "String" to me?
Im new to C++.. Wondering what "string" is and what its used for?
-
April 11th, 2010, 05:58 PM
#2
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.
-
April 11th, 2010, 06:05 PM
#3
Re: Could someone please explain "String" to me?
Originally Posted by UpcomingChris
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() );
-
April 12th, 2010, 06:54 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|