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