Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Compile C++ Code Using The Terminal Directly Without Save File.cpp

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading