程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> C++ Primer Chapter 1,primerchapter

C++ Primer Chapter 1,primerchapter

編輯:C++入門知識

C++ Primer Chapter 1,primerchapter


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.

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved