ch2-HelloStrings (String operations)

Chapter_2     Exercise_2-2     CallHello HeYou     Exercise_2-3







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!
*/









Chapter_2     Exercise_2-2     CallHello BACK_TO_TOP HeYou     Exercise_2-3



Comments

Popular posts from this blog

Contents