Beginning Programming with C++ For Dummies. Davis Stephen R.
from the many types of targets offered.
2. Select Console Application and select Go.
Code::Blocks responds with the display shown in Figure 2-12. Here Code::Blocks is offering you the option to create either a C or a C++ program.
3. Select C++ and click Next.
Figure 2-12: Select C++ as your language of choice.
Code::Blocks opens a dialog box where you’ll enter the name and optional subfolder for your project. First, click the little … button to create a folder to hold your projects, and navigate to the root of your working disk (on a Windows machine, it’ll be either C or D, most likely C). Select the Make New Folder button at the bottom left of the window. Name the new folder Beginning_Programming-CPP.
4. Click OK when your display looks like the one shown in Figure 2-13.
Figure 2-13: Create the folder Beginning_Programming-CPP into which you’ll collect your C++ projects.
Now enter the name of the Project as HelloWorld. Notice that Code:: Blocks automatically creates a subfolder of the same name to contain the files that make up the project.
5. Click Next when your display looks like Figure 2-14.
Figure 2-14: Call your first project HelloWorld.
6. When Code::Blocks asks how you want your subfolders set up, you can accept the default configuration, as shown in Figure 2-15. Select Finish.
Figure 2-15: Select Finish on the final page to complete the creation of the HelloWorld Project.
Code::Blocks creates a console application project – and even populates it with a working program – when you select Finish on the Project Wizard. To see that program, click the plus (+) sign next to Sources in the Management window on the left side of the display. The drop-down list reveals one file, main.cpp. Double-click main.cpp to display the following simple program in the source code entry window on the right:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
It’s okay to skip over what some of this stuff means for now, but the crux of the program starts after the open brace following main(). This is where execution begins. The line
cout << "Hello world!" << endl;
says to output the line "Hello, world!" to the cout, which by default is the command line. The next line
return 0;
causes control to return to the operating system, which effectively terminates the program.
1. Select Build⇒Build to build the C++ source statements into an executable machine language program.
(You can press Ctrl+F9 or click the Build icon if you prefer.) Immediately, you should see the Build Log tab appear in the lower-right screen followed by a series of lengthy commands, as shown in Figure 2-16. This is Code::Blocks telling the C++ compiler how to build the test program using the settings stored in the project file. The details aren’t important. What is important, however, is that the final two lines of the Build Log window should be
Process terminated with status 0 (0 minutes, 1 seconds)
0 errors, 0 warnings
The terminated status of 0 means that the build process worked properly. The “0 errors, 0 warnings” means that the program compiled without errors or warnings. (The build time of 1 second is not important.)
● You already had a gcc compiler installed on your computer before you installed Code::Blocks. Code::Blocks uses a special version of the GNU gcc compiler, but it will use any other gcc compiler that you may already have installed on your computer. Your safest bet is to uninstall Code::Blocks, uninstall your other gcc compiler, and reinstall Code::Blocks from scratch.
● You built your project in a directory that contains a space in the name; for example, you built your project on the Desktop. Be sure to build your project in the folder Beginning_Programming-CPP in the root of your user disk (most likely C on a Windows machine).
Figure 2-16: Building the default program should result in a working program with no errors and no warnings.
Конец ознакомительного фрагмента.
Текст предоставлен ООО «ЛитРес».
Прочитайте эту книгу целиком, купив полную легальную версию на ЛитРес.
Безопасно оплатить книгу можно банковской картой Visa, MasterCard, Maestro, со счета мобильного телефона, с платежного терминала, в салоне МТС или Связной, через PayPal, WebMoney, Яндекс.Деньги, QIWI Кошелек, бонусными картами или другим удобным Вам способом.