std::string s; vs. char s[10];
"jacaranda" is a character-array literal.
char prompt[5] = "hello";
string.h utilities: strcpy(), strcat() and friends.
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.
std::string word1 = "what?" std::string word2 word2 = word1 word1[4] = '!' // word2[4] == '?'
+ does string catenation.
+= does appending.
filename += ".h";
== works as expected.
< define a lexicographic (dictionary) order.
>> and << work as expected.
>> eats white space; stops at white space.
getline() function doesn't eat white space.
getline() is defined in <string>.
.getline() istream member function.
char line[1024]; std::cin >> line;
c_str(), data(), and copy() member function.
c_str().
s changes, so might s.c_str().
s = c, s += c, s.push_back('!').
<string>.
[ ] subscript access.
This page last modified on 23 January 2004.