为什么我的代码在终端中没有输出任何内容.开始新行没有错误

Why does my code not output anything in the terminal. Starts a new line no errors

本文关键字:任何内 输出 开始 有错误 新行没 代码 我的 终端 为什么      更新时间:2023-10-16

这是我在C++文件中的代码:

#include <iostream> 
using namespace std;
int main()
{
cout << "Hello World" << endl;
return 0;
}

我的编译器是Clang。是的,我确实在终端中输入了"clang++"。问题是,它运行它并且不输出任何内容。它只是开始一条新行。 我正在运行 Clang 版本 3.8.0。

正如你所说,clang++ 是编译器,也就是说,它将你的代码转换为可以执行的二进制文件。它不执行程序本身。

默认情况下,编译后的文件名是a.out,因此编译后,要执行程序,您应该运行:

./a.out

您可以像这样指定输出文件名:

clang++ infile.cpp -o outfile

然后运行二进制文件:

./outfile