#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.
1. a small C++ program
#include <iostream>
int main()
{
std::cout<<"Hello, World."<<std::endl;
return 0;
}
(1) The // Characters begin a comment, which extends to the end of the line.
(2) On #include, many c++ facilities are part of standard library rather than being part of core language.
(3) The main function is required to yield a integer as a result. A zero value indicates success, any other value means there was a problem.
2. Some concepts
comment, core language, standard library, #include directives, angle brackets, standard headers, function, statements, curly brackets, output operator, standard output stream, expression, result, side effect, type, left-associative, manipulator, scope, namespace, scope operator, qualified name, free form, string literals, definitions, main function, semicolons, expression statement, null statement.
这本书是我的第一本C/C++ 正式学习书籍,之所以说是正式,是因为原来看过谭浩强的C++,以及一本C++简读本的书籍,发现当时浪费了大量时间,如果刚开始就这本加速C++学起来,效果可能会更好,这本书的确写得非常好,作者从初学者角度将例子贯穿与知识点,教学方法非常独特,相比与国内很多只是写一堆理论,然后给几个例子和习题来说,作者在这本书的写作上用了很多的功夫来思考,将这本书从头到尾看完,你将会第一步感受到一个C++的概貌,当然,这本书又是比较薄,自然会有很多细节知识点和惯用法没有涉及到,但是,学习的本质不就是掌握核心理论,然后在实践中不停的补充新的知识么,所以推荐这本书看过去学习经典C++牛人的书The C++ Programming Language,目前正在钻研,感觉写的很好,如果在学习的过程中能够接触实际的项目锻炼,提高会更加的快,希望大家都能学好用好C++,为自己的具体实践工作打好基础
读完c++ primer,再读完ac++,惊叹于koenig夫妇竟用如此紧凑的篇幅展示c++诱人的魅力,的确是c++很好的入门书籍……正像作者所说,“once you have written enough programs that use the material that we have covered so far, you will no longer need the detailed tutorial style that we have adopted in this book. Instead, you will have gained enough C++ programming experience that you will be able to take advantage of books that contain more detailed information, and less explanation, than this one”.,等把这本书题目写完后,果断看the c++ programming language & generic programming and the stl……
There is an old story about a visitor who has become lost in New York, with tickets in hand to a piano recital. Stopping a passerby, the visitor asks,"Excuse me.Can you tell me how to get to Carnegie Hall?" The answer :"Practice!"
这本书,可能是最好的起点之一,当然,绝对不是学习的终点。我在啃了4遍C++ Primer,钻研了几遍effective,more effevtive,作出了一些小的项目之后,回头来看这本书,觉得本书的内容绝对够资格称得上初学者的圣经。本书的译者,靳志伟先生,在翻译过程中,确实是下了一番功夫,在中国能多有一些这样的翻译,将是一大幸事。但是,我对机械工业出版社,将毫无保留我的憎恨之情,是的,憎恨,你们的排版,纸张,印刷。。。给这么一本经典书抹了黑。能不能反思一下,你们已经把thinking in C 这么一本经典给翻译毁了,你们还要错多久?