std::string s; vs. char s[10];
"jacaranda" is a character array constant.
char prompt[5] = "hello";
string.h utilities.
char s1[4] = "red"; char s2[4] = "red"; if (s1 == s2) std::cout << "yes\n";
<string>.
== compares contents, not addresses.
#include <string> to define strings.
std:: prefix.
using std::string; to forego the std:: prefix.
std::string name = "jacaranda";
[ ] subscripts, just like arrays.
0 to n - 1.
.length() member function returns the number of characters in
a string.
[ ] subscript access to strings is not checked.
.at() subscript access is checked.
+ does string catenation.
+= does appending.
filename += ".h";
== works as expected.
< define a lexicographic (dictionary) order.
>> and << work as expected.
>> ats white space; stops at white space.
getline() function doesn't eat white space.
c_str() member function.
s changes, so might s.c_str().
<string>.
[ ] subscript access.
This page last modified on 10 September 2002.