Home > Software design >  Compile C Code Using The Terminal Directly Without Save File.cpp
Compile C Code Using The Terminal Directly Without Save File.cpp

Time:07-10

I need to compile C code directly in the terminal or CLI without saving the file

When is use the below way, It shows me an error.

g   -x c - <<eof
  #include <iostream>
  using namespace std;

  int main()
  {
    cout << "Hello world";
  }
  eof

CodePudding user response:

You are trying to compile a C program using a C compiler.

This works:

g   '-xc  ' - <<eof
#include <iostream>
using namespace std;

int main()
{
    cout << "Hello world";
}
eof

CodePudding user response:

If you are trying to run a C program from a source, this works:

g   -xc   - && ./a out <<eof
#include <iostream>
using namespace std;

int main()
{
    cout << "Hello world";
}
eof
  • Related