C++编译,但执行时出错
C++ compiles but gives error when executed
我是Linux Ubuntu 11.10的新手,有基本的C++公开。
我通过安装了g++
sudo apt-get install build-essential
并在我的主目录中创建了一个目录cpp。然后,我在我的cpp目录中编写了一个程序hello.cpp
#include <iostream>
using namespace std;
int main() {
cout << "Hello !" ; return 0;
}
并使用进行编译
g++ -W hello.cpp -o hello
程序编译时没有任何错误/警告。当我尝试执行文件时
./hello.cpp
我收到错误消息:
line 3: using: command not found
line 6: syntax error near unexpected token `('
line 6: `int main() {'
我试着看了很多帖子,但没能解决这个问题。我在Windows上有VisualStudio,但我更愿意在Ubuntu上学习C++。提前谢谢。
我认为问题在于您试图执行.cpp源文件,而不是生成的可执行文件。请尝试运行./hello
而不是./hello.cpp
,因为hello
是实际的可执行文件。您当前遇到的错误是由于shell解释器被C++语法阻塞导致的,因为它试图将其作为shell脚本运行。
希望这能有所帮助!
相关文章:
- 执行时使用 boost::asio::d eadline_timer 时出错
- 尝试在Windows上执行C++时出错(通过MinGW编译)
- 在另一台 PC 上执行程序时加载 SDL2 共享库时出错
- 在 C/C++ 中使用 MySQL 连接器执行插入到表时出错
- 从 Qt(release) 生成的文件执行.EXE文件时出错
- 在 Qt 中将 x 可执行文件作为按钮事件运行时出错
- g++:尝试执行"jc1"时出错:execvp:没有这样的文件或目录
- 在返回另一个函数的函数中执行程序期间出错
- 可执行文件在运行时出错
- 将 CLANG 构建的可执行文件与 G++-v6 构建的 Boost 库链接时出错
- R6010 执行后出错.if 语句在 for 循环中.[作业][中止已解决,发现新问题]
- 执行 C++ 代码后出错
- 执行尝试树时出错
- 编译后可执行文件出错
- 执行make时出错
- 在C++中使用popen执行perl命令时出错
- libGL 在执行 OpenGL 程序时出错
- "No such file or directory" 使用 makefile 时在 c++ 中执行简单 fstream 时出错
- 在 OpenCV 中执行特征面算法时出错
- 尝试查找执行"cc1d"时出错