// 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!
*/
*****************************************************************************************
*****************************************************************************************
*****************************************************************************************
*****************************************************************************************
*****************************************************************************************
// Saying Hello with C++
#include <iostream> // Stream declarations
#include <string>
using std::string;
using std::cout;
using std::cin;
using std::endl;
int main()
{
int age;
string first, last;
cout << "First name: ";
cin >> first;
cout << "Last name: ";
cin >> last;
cout << "Age: ";
cin >> age;
cout << "Hello, world! My name is " << first << " " << last
<< ". I am " << age << " today!" << endl;
}
/*
g++ HeYou.cpp -o HeYou
./HeYou
First name: John
Last name: Doe
Age: 8
Hello, world! My name is John Doe. I am 8 today!
*/