我试着用一个简单的Hello World程序在Windows 7下测试MinGW,结果出现了以下错误:
C:codehelloworld.cpp:2:2: error: invalid preprocessing directive #INCLUDE
C:codehelloworld.cpp:3:7: error: expected neested-name-specifier before 'namespace'
C:codehelloworld.cpp:3:17: error: expected ';' before 'std'
C:codehelloworld.cpp:3:17: error: 'std' does not name a type
C:codehelloworld.cpp: In function 'int main()':
C:codehelloworld.cpp:7:2: error: 'cout' was not declared in this scope
我最初的代码如下:
//Hello, World
#INCLUDE <iostream>
using namesapce std;
int main()
{
cout << "Hello, world!";
return 0;
}
#include
应该是小写。C++区分大小写。
它应该是小写的。使用#include
。
此外,它是using namespace std;
(namespace
中的拼写错误)。
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, world!";
return 0;
}