Search code examples
c++terminal

C++, Nothing in the output


I'm new to C++, so sorry if this is something too obvious. I coded a very simple file here, but when I run g++ main.cpp, it doesn't give me any output. What am I missing? This is the code:

#include <iostream>
using namespace std;

int main() {
    cout << "Hello World!" << endl;

    return 0;
}

What I expect:

C:\Users\DEEL\Desktop> g++ main.cpp
Hello World!

C:\Users\DEEL\Desktop>

What I got:

C:\Users\DEEL\Desktop> g++ main.cpp
C:\Users\DEEL\Desktop>

But when I run that file in an IDE like Code::Blocks, it runs perfectly. But when I run it in VS Code's terminal or CMD, I get the same problem.


Solution

  • The command g++ main.cpp creates the file a.out or a.exe. After that file is created you need to run it by the command ./a.out on Linux and Mac or a.exe on Windows.