Home > Net >  Getting stdout using vscode mingw gcc
Getting stdout using vscode mingw gcc

Time:06-12

I wanted to extent my c knowledge to c . Using Win10, I installed VSCode and mingw following the tutorials.

Next I created a Hello World test file. It compiles properly without errors. However when I run it from a terminal window, I do not get any output. I am sure its a stupid beginners mistake...

#include <iostream>

using namespace std;

int main(){
    std::cout << "Hello Moon!";
    std::cout.flush();
    return 0;
}

compiling:

Kompilierung wird gestartet...
D:\msys64\mingw64\bin\g  .exe -fdiagnostics-color=always -g3 -Wall "D:\CPLUSPLUS\programs\hello world\hello world.cpp" -o "D:\CPLUSPLUS\programs\hello world\hello world.exe"

Die Kompilierung wurde erfolgreich abgeschlossen.

console:

PS D:\CPLUSPLUS\programs\hello world> "hello world.exe"
hello world.exe
PS D:\CPLUSPLUS\programs\hello world>

so obviously it runs the exe without complaint, however I do not see any output...

Any hints/ideas?

CodePudding user response:

Thanks quimby! that did the job!

actually ist not my c vscode ignorance but the one of powershell (coming from cmd...)

so you are right: powershell did NOT run my program but rather just echo the quoted string.

so ones needs the & operator to do the job.

Problem solved Thanks again.

CodePudding user response:

i guess you need to remove the std:: prefix because you already imported the std

try this

#include <iostream>
using namespace std;

int main(){
    cout << "Hello Moon!";
    return 0;
}
  • Related