2.3 C + + weapon spectrum
The so-called "工欲善其事, its prerequisite", and to do a good job of C + + programming, natural also inseparable from a few decent weapons. Let's take a look at the C + + weapon spectrum which is worthy of our learning. The first place on the weapon spectrum is the C + + integrated development environment. The so-called Integrated development Environment (Integrated development environment,ide) is a set of software for developing C + + programs, typically including code editors, compilers, debuggers, and graphical user interface tools, which are code writing functions, analysis functions, compilation function, debugging function in one of the development software suite. Some of the complex new IDES even incorporate modeling capabilities, test functions, project management, and so on, almost completely covering the entire lifecycle of software development.
Because of the differences between the two platforms, Windows and Linux/unix, the C + + development tools on both platforms are different.
2.3.1 Developing C + + programs with GCC on the Linux/unix platform
In the Linux/unix platform, although there is also a graphical integrated development environment can be used, but in order to achieve efficiency, C + + program development is more in the form of command line. For example, C + + programmers on the Linux/unix platform use VI to edit source code, compile code with GCC, debug code with GDB, and so on. Strictly speaking, these tools are not a complete integrated development environment, they are like "eight", together with a Linux/unix platform under the development of C + + program tool chain, but it is only responsible for the completion of C + + program development of a link. The most important of these is the compilation process that GCC is responsible for.
In the previous example, we completed the creation of a C + + program in a few steps with Visual Studio on the Windows platform, and the same work, if done on the Linux/unix platform, is not so simple. In fact, in the Linux/unix platform, because of the lack of graphical integrated development tools support, C + + programs are basically created with the GCC compiler, and then with other editing debugging tools, in a manual way to complete.
What we typically call the GCC (GNU Compiler Collection) compiler, is actually a generic term for multiple compilers. GCC was originally only able to compile C-language programs, but when C + + became popular, GCC was quickly extended to compile C + + programs. Later, GCC was further expanded to support the compilation of mainstream development languages such as FORTRAN, Objective-c, and Java, becoming a compiler suite. From the GCC application, it is the most commonly used compiler on the Linux/unix platform. At the same time, in the field of embedded development based on Linux/unix platform, GCC is also the most common compiler. In addition, GCC operates on other major operating systems, such as Solaris, Windows, MAC OS X operating systems, and so on. It is the universality of the GCC compiler application that makes it a de facto standard for C + + compilers.
GCC is a command-line execution tool, and if we want to use it to compile a C + + source file, its command format is as follows:
g++ [Compilation options] source file name
Where g++ is the C + + compile command for GCC, and subsequent compilation options are used to control the compiler's compilation behavior. Our common compilation options are:
? -C
This option means compiling only, not linking to an executable file, but compiling the input. CPP source code file to generate a target file with a suffix of. O;
? -O Output file name
This option specifies the name of the output file. If this option is not given when compiling the executable file, GCC will generate the default executable file. On the Windows platform, this file is named A.exe, and on the Linux/unix platform, the corresponding name is a.out;
? -G
Using the "-G" compilation option will generate the symbolic information necessary for the debug tool (for example, GDB), and to debug the source code, we must include this compilation option;
? -O
This option indicates that the compiler will compile and link the program with optimizations. With this option, the entire source code will be optimized during compilation and linking, thus improving the execution efficiency of the executable file to some extent. However, there will be some loss, the use of optimization options, the compilation, link speed will be correspondingly slower;
? -I. Directory name
This option allows you to specify the additional header file directory for GCC. This option is often used when we use a third-party-provided library of functions to add the Include directory of the library as an additional header file directory for GCC.
In fact, there are probably hundreds of more compile options available from g++, and we just need to know these common compilation options. Refer to the appropriate reference manual when you really need additional compilation options.
After understanding the basic use of GCC, we can also linux/ A new HelloWorld.cpp source file is created on the UNIX platform and edited with the same contents as the previous HelloWorld.cpp file, and then we can use the following command to HelloWorld.cpp the source code file g++ Compiled into an executable HelloWorld program:
g++-o-o HelloWorld HelloWorld.cpp through such a simple command, we will HelloWorld.cpp this C + + source file optimization compiled and linked to an executable file HelloWorld. Now execute this executable file, you can use C + + program to say hello to C + + world on the Linux/unix platform:
./helloworldß start the executable file
Hello world! Content of the ß output
The GCC described here is only one of the most important tools in the C + + program development Toolkit on the Linux/unix platform, and it often needs to be used in conjunction with other tools (such as text Editor VI, Auxiliary Compilation tool make, etc.) to form a complete toolchain to achieve a flexible and efficient C + + Development of the program.
2.3.2 developing C + + programs with Visual C + + on the Windows platform
The development of C + + programs on the Windows platform is much simpler than the development of C + + programs on the Linux/unix platform, which relies on tools to cobble together a "eight". On the Windows platform, there are a number of graphical integrated development environments, in addition to the most common Visual Studio we've described earlier, as well as support for cross-platform Eclipse CDT and Code::Blocks, more compact dev-c++, and more. The rational use of these integrated development tools will undoubtedly greatly improve our development efficiency. In many integrated development environments, Visual C + + is the most widely used. It is an important part of Microsoft's development suite in Visual Studio. Since Microsoft introduced Visual C + + 1.0 in 1992, after more than 20 years of continuous development, Visual C + + has become one of the most powerful and widely used graphical application development tools on the Windows platform. In some areas, such as operating system programming, game development, graphic image processing, COM programming, network programming, Visual C + + has incomparable advantages, become the preferred C + + development tool for many programmers.
Visual C + + is very powerful, but it's a bit too complicated to learn and practise C + +, and there are a lot of features that we don't even use at the moment. Too much functionality will interfere with our learning of C + +. To do this, we can choose its simplified version of--visual C + + Express. The simplified version stripped off most of the features that were less common to beginners (such as support for MFC), but retained the most basic functionality necessary for C + + development (such as compilers, standard libraries, code editors, and so on) to fully meet our current needs for the IDE. If we just want to learn and practice c++,visual C + + Express on the Windows platform, it should be our best choice.
2.4 C + + World Travel essentials
Each traveler's backpack has a Swiss Army knife and a bottle of Yunnan. Similarly, there are several handy tools in every C + + world traveler's backpack.
2.4.1 Time Machine-code Configuration Management tool Visual Source Safe
In the actual development process, often encounter this situation: in order to verify the feasibility of a scenario, we modified the source code files, but later found that the scheme does not work, to return to the original unchanged state, but found that the code has been changed by us, and can not go back. At this point we would like to think, if there is a time machine, can go back to the past, to retrieve the original code has not been modified how good ah. Fortunately, Microsoft has prepared such a tool for US--visual SourceSafe (VSS), which is a time machine that allows us to get back to the past and retrieve the code.
Essentially, VSS is a source-code configuration Management tool that allows you to make security changes to existing code. The basic process is this: All files in the project are saved on the server, and the code files need to be checked out from the server (check out) to local modifications before each code is modified, and then the code files are checked in from the local (check in) to the server after the modification is complete. Each check-in and checkout leaves a corresponding timestamp on the server, which is equivalent to taking a photo of the code at the time. If you find that a modification introduces a new error and you want to get the code before it is modified, you can roll back the code to a point in time before the modification and restore the previous code with the photo that was taken at that time. It's like having a time machine that allows us to traverse through the code's history of change, and it won't happen again because of the mistakes you want to go back to before you change it. It also keeps track of changes experienced by the code as users, projects, and time change, making it easy to maintain code updates.
2.4.2 CodeProject and Stack Overflow
In the 1th chapter once introduced, the only way to learn C + + is "read more and write more thinking". Reading more is to read other people's excellent code and even the lessons of others. On the CodeProject website, we can find a lot of good sample code, while on the stack Overflow website, more is the valuable programming experience of others. Both of these sites should be our "read more" objects.
1. CodeProject
CodeProject (http://www.codeproject.com) is a well-known technology community for Windows programming, and the main users are programmers on the Windows platform. The biggest feature of the site is that the technical articles not only introduce a specific development technology, but also provide the corresponding source code download. Let's not only have a look, but also have practice.
2. Stack Overflow
Stack Overflow (http://stackoverflow.com) is a design-related IT technology question and answer site, in addition to C + +, it also covers the C #, Java, PHP and other popular technology areas. Users can submit their own problems in the development process for free, browse the questions of other users and the best answers after voting, and search for questions of interest to them, etc. The questions and answers in Stack overflow come from concrete practice, often in our own problems encountered in actual programming, where we can find ready-made answers. More importantly, the answers to these questions are from highly skilled and experienced programmers all over the world and are ranked by the user by voting, so the quality of the answers is particularly high. Stack overflow has now become the most popular technology quiz site in the global IT community.
So, if we encounter any difficult problems in our study, we can go here to ask and seek answers from all over the world. Even if there is no problem, you can often go around here to see other people encountered problems and the corresponding solution, you might later encounter similar problems, you know how to solve.
2.4.3 C + + dictionary--cplusplus.com
Learning English is an indispensable English dictionary. Similarly, learning the C + + language, there is also a C + + dictionary.
Cplusplus.com (http://www.cplusplus.com) is a C + + dictionary. It contains basic information about C + + (summary description of C + +, history of development, FAQs, etc.), technical documentation (Introduction and tutorials of C + + features), standard library indexes (detailed descriptions of important classes, functions, objects, etc. in the standard library, and provides short examples) and forums. In the process of learning, we often need to look at the use of a library function, or a class of member functions, and so on, which almost all can find the most authoritative explanation, and it also has a short example, so that we can use the method at a glance. Really can say is a stand in hand, everything is worry-free.
Original address: http://www.cnblogs.com/nihaoCPP/p/3961997.html
(reprint) Hello, C + + (6) 2.3 C + + weapon spectrum