我正在尝试执行我的第一个"Hello World!" 在C++中.我使用的是Windows XP,我安装了cygwin,其中安装了g ++ C++编译器.我写了一个小的hello-world程序,并将其保存在hello.cpp中.从命令提示符我写:
g ++ hello.cpp
但我得到:
'g ++'不被识别为内部或外部命令,可操作程序或批处理文件.
我在我的D:\ programs\cygwin中安装了cygwin.我在D:\ cpp中使用我的hello-world文件创建了另一个目录.我的安装或路径的东西似乎不好,但我无法弄清楚是什么.我运行了cygwin的exe文件,在安装目录中我有所有必需的文件,我认为:bin文件夹,lib,Cygwin.bat等.
我已经读过,如果出现此类错误消息,我应该检查cygwin1.dll文件是否已复制到Windows的主文件夹中.这是C:\ WINDOWS目录吗?我看过那里,我那里没有这样的文件.我在cygwin的bin文件夹中有cygwin1.dll:D:\ programs\cygwin\bin.另外,如何在命令的搜索路径中检查bin文件夹(D:\ programs\cygwin\bin)?
我认为hello-world程序不应该包含任何语法错误,我刚刚复制了它.还有,当我写的时候
g ++ -v
我收到相同的错误消息:该命令无法识别.如果有人给我一个暗示我应该看什么,我将不胜感激.谢谢.
这是hello-world程序的代码:
#include <iostream>
using namespace std;
int main() {
cout <<"Hello World!"<<endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我已经安装了g ++,现在当我输入g ++ -v时,我得到:读取规格:\ d\cygnus\cygwin-b20\H-i586-cygwin32\bin ..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\specs gcc version egcs-2.91.57 19980901(egcs-1.1 release)
在bin目录中,我有g ++.exe和gcc.exe.我不明白为什么我得到"gcc"而不是"g ++".我不知道这有多重要,但是当我尝试在DOS命令提示符下编译程序时收到错误消息:
我明白了:
hello.cpp:1: parse error before character 0357
hello.cpp: In function 'int main()':
hello.cpp:'cout' undeclared (first use this function)
hello.cpp: (Each undeclared identifier is reported only once
hello.cpp: for each function it appears in.)
hello.cpp: 'endl' undeclared (first use this function)
Run Code Online (Sandbox Code Playgroud)
这是我尝试在cygwin shell中编译程序时得到的:
hello.cpp:1: parse error before character 0357
hello.cpp: In function 'int main()':
hello.cpp:'cout' undeclared (first use this function)
hello.cpp: (Each undeclared identifier is reported only once
hello.cpp: for each function it appears in.)
hello.cpp: 'endl' undeclared (first use this function)
g++.exe: hello.cpp: No such file or directory
g++.exe: No input files
g++.exe: hello.cpp: No such file or directory
g++.exe: No input files
g++.exe: hello.cpp: No such file or directory
g++.exe: No input files
g++.exe: hello.cpp: No such file or directory
g++.exe: No input files
g++.exe: hello.cpp: No such file or directory
g++.exe: No input files
Run Code Online (Sandbox Code Playgroud)