#include <iostream>
#include <string>
int main()
{
std::cout<<"Your name,please."<<std::endl;
std::string name;
std::cin>>name;
std::cout<<"Hello,"<<name<<"."<<std::endl;
return 0;
}
1. Variable is a place to hold values.
2. A variable is an object that has a name. A object is a part of computer's memory that has a type. It is possible to have an object that don't have a name.
3. Three events cause system to fflush the buffer:(1) buffer is full.(2) read occures.(3)explicitly do it(std::endl).
//output framing name:
#include <iostream>
#include <string>
int main()
{
std::cout<<"Your name,please."<<std::endl;
std::string name;
std::cin>>name;
const std::string greeting = std::string("* ") + "Hello, " + name + "! *";
int len = greeting.length();
const std::string decoration(len,'*');
std::string hallow(len-2,' ');
hallow = "*" + hallow + "*";
std::cout<<decoration<<std::endl<<hallow<<std::endl<<greeting<<std::endl<<hallow<<std::endl<<decoration<<std::endl;
return 0;
}
Three new ideas:
(1) We can give a variable a value as we define it.
(2) We can use '+' to concatenate a string and a string literal. We can say '+' is overloaded.
(3) We can use const as a part of the definition, indicating that the value of that variable won't change in the rest of its lifetime.
A good property of an operator that never changes is its associativity.'+' is still left-associative.