在Windows XP上编译C ++程序

时间:2009-03-06 22:46:22

标签: c++ windows

我在Windows XP上用C ++运行一个简单的Hello-world程序时遇到问题。我在这里写了一篇文章:

  

Using the g++ C++ compiler from cygwin

我说了问题,我收到了很多有用的回复,解决了一些问题。但是,我仍然无法运行我的hello-world程序。请看一下帖子,我已将程序包括在内。我的一个朋友可以毫无问题地在他的机器上运行这个程序。所以,问题应该在我的系统或库或其他东西,但我无法弄清楚是什么。在我的帖子的“编辑”部分,我已经包含了我得到的错误消息。

以下是我尝试编译程序时收到的内容:

  

g ++ hello.cpp

来自cygwin shell:

当我尝试g ++ hello.cpp时,我得到:

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

以下是我尝试从DOS命令提示符编译程序(再次使用g ++ hello.cpp)时得到的结果:

当我尝试g ++ hello.cpp时,我得到:

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)

2 个答案:

答案 0 :(得分:2)

您的代码中包含非法字符;它可能是由不良的字符编码或类似的东西引起的。试着检查一下。

答案 1 :(得分:2)

看起来你的代码中有某种非法字符。您是自己输入代码还是复制&粘贴吗?如果是后者,您复制的源可能会以某种方式怀疑 - 自己将代码输入编辑器,保存并重新编译。