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
>Solution :
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