Learning Cpp----Comliling your first program
IDE: Visual Studio 2008
Project Type: Console Application
Point 1:the first program is "Hello world" for a new language
Traditionally, the first program programmers write in a new language is the infamous hello world program, and we aren’t going to deprive you of that experience! You’ll thank us later. Maybe.The fact is very funny! The code is following:
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout <<"Hello World!" <<endl;
return 0;
}
Point 2: about "stdafx.h"
Important note to Visual Studio users: Visual studio programs should ALWAYS begin with the following line:
#include "stdafx.h"
Otherwise you will receive a compiler warning, such as c:\test\test.cpp(21) : fatal error C1010: unexpected end of file while looking for precompiled header directive.
Alternately, you can turn off precompiled headers. However, using precompiled headers will make your program compile much faster, so we recommend leaving them on
unless you are developing a cross-platform program.
Point 3: about "iostream.h"
This header file privide the input/output methods for console programming:
input:cin
output:cout
for example:
#include "stdafx.h" #include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { int x = 0; cout <<"Enter one integer:"; cin >> x; cout <<"The integer you entered is:" << x << endl; return 0; }
posted on 2010-12-23 10:50 MaggieNing 阅读(196) 评论(0) 编辑 收藏 举报