chapter 1_Accelerated C++书评-查字典图书网
查字典图书网
当前位置: 查字典 > 图书网 > 科技 > Accelerated C++ > chapter 1
C.L. Accelerated C++ 的书评 发表时间:2013-07-29 22:07:45

chapter 1

#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.

展开全文


推荐文章

猜你喜欢

附近的人在看

推荐阅读

拓展阅读