简体   繁体   English

在终端运行 C++ 程序

[英]Run C++ program in Terminal

I'm trying to run this simple C++ code in Sublime Text on Terminal but it's not exactly working...我正在尝试在终端上的 Sublime Text 中运行这个简单的 C++ 代码,但它并不能正常工作......

#include <iostream>
using namespace std;

int main() {

    cout << "Hello world!" << endl;
    return 0;

}

I'm getting this message instead:我收到这条消息:

"hello_world2.cpp:1:10: fatal error: 'iostream' file not found" “hello_world2.cpp:1:10: 致命错误:找不到‘iostream’文件”

How can I fix this?我怎样才能解决这个问题?

You most probably are missing development headers for your C++ standard library.您很可能缺少 C++ 标准库的开发头文件。

You didn't say anything about your environment, but if you were on Windows on Mac you would for sure get these together with your compiler, so let's assume Linux.您没有提及您的环境,但如果您在 Mac 上使用 Windows,您肯定会将这些与您的编译器放在一起,所以让我们假设 Linux。

  • You need to install libstdc++-devel package or equivalent ( libstdc++-4.8-dev etc.)您需要安装libstdc++-devel包或等效包( libstdc++-4.8-dev等)

In terminal (make sure you're in correct directory), type g++ {{ file_name }} .在终端中(确保您在正确的目录中),输入g++ {{ file_name }} This command will generate an output file named with 'a.exe' and you have to just execute that.此命令将生成一个名为“a.exe”的 output 文件,您只需执行该文件即可。 Type .\a.exe to execute that output file.键入.\a.exe以执行该 output 文件。 enter image description here在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM