码迷,mamicode.com
首页 > 编程语言 > 详细

C++ Primer Chapter 1

时间:2015-02-12 21:26:01      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:

When I start reviewing, I thought Chapter is useless. Because the title is “Getting Start” . I thought that is useless. But I found something I miss before, so I review it and found I understand something that confused me. So every parts is useful in this book.

The first function is very simple so we don’t have to explain it anymore. But how to compile it? I don’t think the book write well in this part. I will show you how to use cmd to compile it in Windows but I don’t have a Linux PC so I can’t show how to compile it in Linux.

1.    You should install VC. I install Visual Studio 2013 so I have VC.

2.    Locate your VC. Like me, my VC is locate here C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC

3.    Right click “This PC” and click “Properties” .Advanced system settings->Advanced->Environment Variables. Find “path” in “User Variable for XXX” .If there is no “path”, create one. Also, create two variable named “include” and “lib”.

4.    Edit “path” by adding two addresses. First is where your VC/bin are. For me is “C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin”. Second is in your “Microsoft Visual Studio X.0/Common7\IDE” folder. For me is “C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE”.

5.    Edit “lib” by adding two addresses. First is where your VC/lib are. For me is “C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib”. Then use search where uuid.lib are. And add the address of it. You should separate two addresses by adding “;”.

6.    Edit “include” by adding where your VC/include are. For me is C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include.

7.    OK, now you have done building your developing environment. You can use cmd to compile your program in the way the book introduces in p.5.

I/O is not defined by the language itself so we should define it by using the IO library named iostream. A stream is a sequence of characters read from or written to an IO device. But remember cin and cout is an object of type istream and ostream. This is important to remember that cin is not the same as istream and cout is not the same as ostream. We include a header by using “#include”. We will know in the following chapter that if we writer our own header, we should use #include “(your header)” (double quotes) and the standard library #include<(library)>.

endl can end the current line. However “\n” can also do that. The different between them is that endl can flush the buffer. This ensures that all the output is written to the output stream rather than staying in the memory. For me, I prefer using endl.

Namespace is useful, it can, to some degree, avoid some mistake we may make. All names defines by the standard library are in the std namespace.

For flow of control, I will discuss it in the following article.

Class, I think, is the most important part in C++. By writing a class we can define our own data structure. A class defines a type. Sometime you will see a program that the source is just a few line but has a lot of class and the class is complicate. Member function is defined in the class. We can decide what the member function when we write the class. We can use the member function by using the dot operator (“.”) . Like the main function, when we use a function, we should use a call operator, no matter if there is any arguments.

OK, that’ all. That is what the chapter 1 says. I will write something about Chapter 2 in the next blog.

C++ Primer Chapter 1

标签:

原文地址:http://www.cnblogs.com/hxueh/p/4288887.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!