dimanche 27 septembre 2020

Can you update the g++ command to compile with c++11 by default?

I'm new to c++ programming, and I'm also using emacs to write code in instead of using an IDE because my friend said getting comfortable with terminal and emacs will benefit me later on.

That said, I have to constantly compile my programs in the terminal using "g++ <file_name_here>" It's been great until today, when trying to learn vectors.

Here is the problem I ran into when I tried to compile like this: ~/Documents/cpp/cpp_practice master ?5 > g++ vector_prac_1.cpp

vector_prac_1.cpp:16:27: error: expected ';' at end of declaration
  vector <int> test_scores {100, 98, 89, 85, 93}; // you can also initialize elements just like array
                          ^
                          ;

Then after looking around I decided to try to compile with "g++ -std=c++11 vector_prac_1.cpp" And it worked with no problems.

So should I just compile everything with "g++ -std=c++11 <file_name_here>" from now on? Or is there a way to change something so I'm always compiling that way by default?

Aucun commentaire:

Enregistrer un commentaire