我正在制作一个简单的 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/