【问题标题】:Compiling C++ program on Windows XP在 Windows XP 上编译 C++ 程序
【发布时间】:2009-03-06 22:46:22
【问题描述】:

我在 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)

【问题讨论】:

    标签: c++ windows


    【解决方案1】:

    您的代码中似乎有某种非法字符。您是自己输入代码还是复制粘贴?如果是后者,您复制的源代码可能在某些方面受到怀疑 - 自己将代码输入到编辑器中,保存并重新编译。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-12
        • 2012-04-17
        相关资源
        最近更新 更多