C++ Quick Syntax Reference 无水印pdf

所需积分/C币:10 2017-09-22 11:47:25 1.98MB PDF
22
收藏 收藏
举报

C++ Quick Syntax Reference 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Contents at a glance About the author About the technical reviewer Introduction u XvI Chapter 1: Hello World Chapter 2: Compile and run ammann 3 Chapter 3: Variables a 5 Chapter 4: Operators Chapter 5: Pointers mmamamammammmmmm 15 Chapter 6: References 19 Chapter 7: Arrays nn. ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■口 21 Chapter 8: String a23 Chapter 9: Conditionals 27 Chapter 10: Loops. IIRaaaaaIRaaIIEaIIII 29 Chapter 11: Functions Chapter 12: Class 37 Chapter 13: Constructor ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ Chapter 14: Inheritance ■■■■■■■■■ 45 Chapter 15: Overriding mmm n 47 Chapter 16: Access Levels ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 51 CONTENTS AT A GLANCE Chapter 17: Static. ■■■■■■■■■■■■■■■■■■■■ n55 Chapter 18: Enum 57 Chapter19: Struct and uni0n,,,,,…,,,,…,m,59 Chapter 20: Operator Overloading. naaman a63 Chapter 21: Custom Conversions mat 67 Chapter 22: Namespaces mmmmmm 69 Chapter 23: Constants nt u73 Chapter 24: Preprocessor IIn 77 Chapter 25: Exception Handling mmmaammaaamaamma 83 Chapter 26: Type Conversions u87 Chapter 27: Templates ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 93 Chapter 28: Headers g99 Index n103 Introduction C++ is a general purpose multi-paradigm programming language. It is an extension of the C language and as such most C code can easily be made to compile in C++. Some of the major additions to C include object-orientated programming, operator overloading, multiple inheritance and exception handling The development of C++ began in 1979, seven years after C first made its appearance Despite being what many consider legacy languages, C and C++ are still the most widely used languages in the software industry. They are used in creating everything from operating systems and embedded software to desktop applications, games and so on Compared with newer languages, C++ applications are often more complex and take longer to develop. In return, C++ gives the programmer a tremendous amount of control in that the language provides both high-level and low-level abstractions from the hardware. It is also designed to give the programmer a lot of freedom by supporting many different programming styles or paradigms, such as procedural, object-oriented or generic programming. The compiler used in this book is the Microsoft C++ compiler. Some other common ones include borland, Intel and GNU C++ compilers. Despite C++ being standardized in 1998, these compilers still support slightly different features. Therefore, when something applies specifically to the Microsoft compiler this will be pointed out XVIl CHAPTER 1 Hello world Choosing an IDE To begin developing in C++ you should download and install an Integrated Development Environment(IDe)that supports C++. a good choice is Microsoft's own Visual Studio If you do not have visual studio but would like to try out the examples in this book in a similar environment you can download visual Studio Express from microsoft's website This is a lightweight version of Visual Studio that is available for free alternatively you can develop using a simple text editor -such as Notepad-although this is less convenient than using an IDE. If you choose to do so, just create an empty document with a cpp file extension and open it in the editor of your choice Creating a project After installing Visual Studio or Visual Studio Express, go ahead and launch the program You then need to create a project, which will manage the c++ source files and other resources. Go to File >New > Project in Visual Studio, or File New Project in Visual Studio Express, to display the new project window. From there select the Visual C++ template type in the left frame. Then select the Win32 Console Application template in the right frame At the bottom of the window you can configure the name and location of the project. When you are finished, click the oK button and another dialog box will appear titled Win32 Application Wizard. Click next and a couple of application settings will be displayed. Leave the application type as Console application and check the Empty project checkbox. Then click Finish to let the wizard create your empty project Adding a source file You have now created a C++ project. In the Solution Explorer pane (view > Solution Explorer) you can see that the project consists of three empty folders: Header Files Resource Files and Source Files. Right click on the Source Files folder and select Add > New Item From the Add New Item dialog box choose the C++ File( cpp) template Give this source file the name"MyApp"and click the Add button. An empty cpp file will now be added to your project and also opened for you Ihttp://www.microsoft.com/visualstudio zhttp://www.microsoft.com/express CHAPTER1■ ELLO WORLD Hello world The first thing to add to the source file is the main function. This is the entry point of the program, and the code inside of the curly brackets is what will be executed when the program runs. The brackets, along with their content, is referred to as a code block or just a block int main( The first application will simply output the text"Hello World"to the screen. Before this can be done the iostream header needs to be included This header provides input and output functionality for the program, and is one of the standard libraries that come with all C++ compilers. What the #include directive does is effectively to replace the line with everything in the specified header before the file is compiled into an executable #include iostream> int main()仍 With iostream included you gain access to several new functions. These are all located in the standard namespace called std, which you can examine by using a double colon, also called the scope resolution operator (: After typing this in Visual Studio, the IntelliSense window will automatically open, displaying what the namespace contains Among the members you find the cout stream, which is the standard output stream in C++ that will be used to print text to a console window It uses two less-than signs known as the insertion operator(<) to indicate what to output. The string can then be specified, delimited by double quotes, and followed by a semicolon The semicolon is used in C++ to mark the end of all statements #include <iostream> int main( std: cout < Hello World" Using namespace To make things a bit easier you can add a line specifying that the code file uses the standard namespace. You then no longer have to prefix cout with the namespace(std: since it is now used by default #include <iostream> using namespace st int maino cout < Hello World CHAPTER 2 Compile and run Visual Studio compilation Continuing from the last chapter, the hello world program is now complete and ready to be compiled and run. You can do this by going to the Debug menu and clicking on Start Without Debugging(Ctrl+F5). Visual Studio then compiles and runs the application which displays the text in a console window If you select Start Debugging(F5) from the Debug menu instead, the console window displaying Hello world will close as soon as the main function is finished. To prevent this you can add a call to the cin: get function at the end of main. This function, belonging to the console input stream, will read input from the keyboard until the return key is pressed #include <iostream> using namespace std int maino cout << hello world cin. geto Console compilation As an alternative to using an ide you can also compile source files from the command line as long as you have a C++ compiler. For example, on a Linux machine you can use the gNu C++ compiler, which is available on virtually all Unix systems. You type the compiler name" g++and give it the input and output filenames as arguments. It then produces an executable, which when run gives the same result as one compiled under Windows 8++ MyApp. cpp -o MyApp.exe yaPp.exe Hello world http://www2.reSearCh.att.com/bs/compilers.html CHAPTER 2 COMPILE AND RUN Comments C++ has two kinds of comment notations- single-line and multi-line. These are used to insert notes into the source code and will have no effect on the end program / single-line comment / multi-line ommen * CHAPTER 3 Variables Variables are used for storing data during program execution Data types Depending on what data you need to store there are several kinds of built-in data types These are often called fundamental data types or primitives. The integer(whole number) types are short, int and long. The float, double and long double types are floating-point (real number types. The char type holds a single character and the bool type contains either a true or false value Data Type Size(byte) Description char Integer or character short nt 24448 Integer long double Floating-point number long double 8 bool Boolean value In C++, the exact size and range of the data types are not fixed. Instead they are dependent on the system for which the program is compiled. The sizes shown in the table above are those found on most 32-bit systems and are given in C++ bytes. a byte in C++ is the minimum addressable unit of memory, which is guaranteed to be at least 8 bits, but might also be 16 or 32 bits depending on the system. By definition, a char in C++ is l byte in size. Furthermore, the int type will have the same size as the processor's word size, so for a 32-bit system the integers will be 32 bits in size. Each integer type in the table must also be at least as large as the one preceding it. The same applies to floating-point types where each one must provide at least as much precision as the preceding one

...展开详情
试读 108P C++ Quick Syntax Reference 无水印pdf
立即下载 身份认证后 购VIP低至7折
一个资源只可评论一次,评论内容不能少于5个字
您会向同学/朋友/同事推荐我们的CSDN下载吗?
谢谢参与!您的真实评价是我们改进的动力~
  • 至尊王者

关注 私信
上传资源赚钱or赚积分
最新推荐
C++ Quick Syntax Reference 无水印pdf 10积分/C币 立即下载
1/108
C++ Quick Syntax Reference 无水印pdf第1页
C++ Quick Syntax Reference 无水印pdf第2页
C++ Quick Syntax Reference 无水印pdf第3页
C++ Quick Syntax Reference 无水印pdf第4页
C++ Quick Syntax Reference 无水印pdf第5页
C++ Quick Syntax Reference 无水印pdf第6页
C++ Quick Syntax Reference 无水印pdf第7页
C++ Quick Syntax Reference 无水印pdf第8页
C++ Quick Syntax Reference 无水印pdf第9页
C++ Quick Syntax Reference 无水印pdf第10页
C++ Quick Syntax Reference 无水印pdf第11页
C++ Quick Syntax Reference 无水印pdf第12页
C++ Quick Syntax Reference 无水印pdf第13页
C++ Quick Syntax Reference 无水印pdf第14页
C++ Quick Syntax Reference 无水印pdf第15页
C++ Quick Syntax Reference 无水印pdf第16页
C++ Quick Syntax Reference 无水印pdf第17页
C++ Quick Syntax Reference 无水印pdf第18页
C++ Quick Syntax Reference 无水印pdf第19页
C++ Quick Syntax Reference 无水印pdf第20页

试读结束, 可继续阅读

10积分/C币 立即下载