Home > Mobile >  C , Nothing in the output
C , Nothing in the output

Time:03-15

I am new to C and coded my first main.cpp but I got an error, not exactly an error, it is a logical error, I guess because I wrote the following code:

#include <iostream> // including the iostream
using namespace std; // using the std namespace

int main() { // starting the main function
    cout << "Hello World!" << endl; // My favorite line of code in all the of languages
    return 0; // returning 0 to stop the function execution
}

In the terminal I expected

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

C:\Users\DELL\Desktop> 

But it is just showing:

C:\Users\DELL\Desktop> g   main.cpp

C:\Users\DELL\Desktop> 

No output is coming, but when I try in Code::Blocks, it is working just fine! In vscode terminal, the same problem but when I run the file, it is working again! Why is it not working? I tried it in Command Prompt, installed the Windows Terminal, and tried it in that also (keeping the terminal as Command Prompt, cause I don't know what PowerShell is and how to use it) but any method is not working.

Please tell me what to do, I am new to c and know only some things amount it.

CodePudding user response:

It's pretty simple, after g "file.cpp", you get an output file in your current working directory, which is the executable. C is compiled, not interpreted.

That output file is the executable, which by default will be "a.out", with gcc/g . You can use the option "-o" to specify the output directory.

CodePudding user response:

g main.cpp will compile the file and produce a.exe, you just need to type a.exe in the terminal and it will print Hello World!.

CodePudding user response:

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.

  • Related