c++ - 用树莓派运行 C++ 文件

标签 c++ raspberry-pi

我正在制作一个简单的 hello world c++ 程序。出于某种原因,我编译后它不会运行。这是程序:

#include <iostream>
using namespace std;

int main() {
    cout << "hello world";
}

我编译使用:

g++ -std=c++0x helloworld.cpp

没有错误。但是,当我尝试使用 ./helloworld.cpp 运行它时,我得到了这个:

./helloworld.cpp: line 2: using: command not found
./helloworld.cpp: line 5: syntax error near unexpected token `('
./helloworld.cpp: line 5: `int main()'

当然,我尝试查找它,并找到了一个链接,上面有人问了几乎与我完全相同的问题。 (C++ compiles but gives error when executed)。他们告诉我删除 .cpp。但是,我尝试执行 ./helloworld,但仍然出现错误。它告诉我:

bash: helloworld: No such file or directory

此外,我在其中包含 helloworld.cpp 的目录中,所以我认为这不是问题所在。任何帮助,将不胜感激。谢谢!

最佳答案

g++ -std=c++0x helloworld.cpp

应该给您留下一个您可以执行的 a.out 文件。

However, when I tried running it using ./helloworld.cpp, I got this:
...

您不能从 shell 中执行 helloworld.cpp 源代码。


你可能应该使用

g++ -std=c++0x helloworld.cpp -o helloworld
                            # ^^^^^^^^^^^^^

将可执行文件命名为a.out

然后你可以调用./helloworld来运行你编译好的程序。

关于c++ - 用树莓派运行 C++ 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37737860/

相关文章:

c++ - 函数指针数组模板

c++ - 转到文件中的特定行并阅读它

python - 如何将 QuTip 添加到 canopy?因为试了很多次,每次都报错。

python - 如何在 python 中将 16 位 PCM 数据转换为 float ?

Linux 脚本在重启后无法正常执行

raspberry-pi - 如何通过 JSON-RPC 仅扫描 Kodi 中的特定目录?

python - 如何通过Python打开不同类型的网络浏览器?

c++ - 推力排序示例中的崩溃

java - 在处理草图中将树莓派的蓝牙重新连接到 HC-06

c++ - 用 C 封装 C++ 接口(interface)