HelloStrings.cpp
TCP1, p. 109
download
// The basics of the Standard C++ string class
#include <string>
using std::string;
#include <iostream>
using std::cout;
int main()
{
string s1, s2; // Empty strings
string s3 = "Hello, world!"; // Initialized
string s4("I am"); // Also initialized
s2 = "today"; // Assigning to a string
s1 = s3 + " " + s4; // Combining strings
s1 += " 8 "; // Appending to a string
cout << s1 + s2 + "!\n";
}
/*
g++ HelloStrings.cpp -o HelloStrings
./HelloStrings
Hello, world! I am 8 today!
*/
Comments
Post a Comment