# Change the compiler of c++ 11

This topic is 1880 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

How do i change the compiler of C++ 11 in VS12 to codeblocks compiler

##### Share on other sites
Thanks but i want to change the compiler because I use a book which uses c++ to teach but i feel comfortable using vs 12 and i also need the same results as it is in code blocks. thats why

##### Share on other sites
What is it with the result from VS2012 that is different from codeblocks, or not what you expect or want it to be?

##### Share on other sites
The thing is in codeblocks the console does not end after it starts but in vs it just closes and i can't see a thing, for example use this code in vs and codeblocks in an console app,
 #include <iostream> using namespace std; int main() { //Chapter 2 : Additon code //Chapter 2 : Divisional code int first, second; cout << "Dividing 28 by 14." << endl; first = 28; second = 14; cout << "Quotient " << first / second << endl; cout << "Remainder " << first % second << endl; cout << "Dividing 32 by 6." << endl; first = 32; second = 6; cout << "Quotient " << first / second << endl; cout << "Remainder " << first % second << endl; //chapter 2 : char cout << "Char " << first / second << endl; char ch; ch = 'a'; cout << ch << endl; char c; c = '\0'; cout << c << endl; cout << "hif" << endl; return 0; } 

##### Share on other sites
Ya it is there but when u close it and juz use F5 it closes automatically

##### Share on other sites
As LennyLen said, you can keep the console open after exit in VS also. This is not the result of the compiler, but the result of how the IDE handles your application. So even if you would have used the VS IDE with another compiler, it is still VS that is either keeping the console open or closing it after the program exits.

For example, in VS you can run the application with (F5) or without (CTRL-F5) the debugger. If you run the application with the debugger, the IDE will close the console immediately, and if you run it without the debugger, it will keep the console open after it exits.

##### Share on other sites
Alternately you can just set a break point at the closing brace for the main() function. Just click the margin on the left of the closing brace in the IDE.

##### Share on other sites
Put std::cin.get() (maybe one more) at the end of your program to pause.

##### Share on other sites
Alternatively you can pause your program at the end using something like std::cin.get(); or getchar();

Cheers!

##### Share on other sites
If this is a windows only application you can add the following line at the bottom of the main
 stytem( "pause" ); 

Otherwise should work on any system
 std::cout << "press the enter key to continue" << std::endl; char c; std::cin >> c; 

##### Share on other sites
I really can't recommend against
 system("pause"); 
enough. Especially when you can have highly portable functions available to you in the standard library.

I prefer to use something like:
 void pause_console(char const* message) { std::cout << message << std::flush; std::cin.ignore(std::numeric_limits< std::streamsize >::max(), '\n'); } 

Benefits? Independent of IDE in use and is platform independent.

Incidentally, the MSVC compiler in VS2012 is perfectly fine. I would recommend sticking with it on the Windows platform. In fact, the only reason I use g++ on Windows is to experiment with variadic templates among other things that VS doesn't yet support. For the simple stuff, though, don't sweat over compiler differences too much. Your results should be the same regardless.

##### Share on other sites

I really can't recommend against
 system("pause"); 
enough. Especially when you can have highly portable functions available to you in the standard library.

I prefer to use something like:
 void pause_console(char const* message) { std::cout << message << std::flush; std::cin.ignore(std::numeric_limits< std::streamsize >::max(), '\n'); } 

Benefits? Independent of IDE in use and is platform independent.

Incidentally, the MSVC compiler in VS2012 is perfectly fine. I would recommend sticking with it on the Windows platform. In fact, the only reason I use g++ on Windows is to experiment with variadic templates among other things that VS doesn't yet support. For the simple stuff, though, don't sweat over compiler differences too much. Your results should be the same regardless.

FYI, Microsoft released CTP about a month ago (http://blogs.msdn.com/b/vcblog/archive/2012/11/02/visual-c-c-11-and-the-future-of-c.aspx) that supports variadic templates and few more nice features of C++11. They haven't yet updated Intellisense so its a bit weird because you will get syntax error in some places but it will compile. I used it in my main project for a while and didn't encounter any errors.

I'm not sure when these changes will be incorporated into main version but lets hope it will be soon

##### Share on other sites

that supports variadic templates and few more nice features of C++11.

Wow, thanks for that info! I just installed the first service pack for VS2012, but I didn't see anything about variadic templates in the description - but then again, that was probably because I stopped reading after "enable C++ applications to target Windows XP from Visual Studio 2012". I was so waiting for this. Now I can finally say that there is no reason left to finally ditch the very outdated VS2008 and move to VS2012.

I just went back and read through the MSDN blocks, but none of them said anything about upgrades to the compiler... So I guess I just have to try it ;) Thanks again for the info

##### Share on other sites

[quote name='noizex' timestamp='1354041989' post='5004608']
that supports variadic templates and few more nice features of C++11.

Wow, thanks for that info! I just installed the first service pack for VS2012, but I didn't see anything about variadic templates in the description - but then again, that was probably because I stopped reading after "enable C++ applications to target Windows XP from Visual Studio 2012". I was so waiting for this. Now I can finally say that there is no reason left to finally ditch the very outdated VS2008 and move to VS2012.

I just went back and read through the MSDN blocks, but none of them said anything about upgrades to the compiler... So I guess I just have to try it ;) Thanks again for the info
[/quote]

Its CTP so its a preview of new features that haven't yet been incorporated into main MSVC compiler. You will have to switch compiler in project options to use it. Its supposed to not be used for real purposes until they release the real version, but I used it in my project without problems, as I mentioned already.

##### Share on other sites
The official Update 1 was just released yesterday. It's not a preview anymore.

##### Share on other sites

The official Update 1 was just released yesterday. It's not a preview anymore.

This update does not contain the features from the november CTP though

##### Share on other sites

[quote name='BigDaveDev' timestamp='1353870914' post='5003980']
-snip -

FYI, Microsoft released CTP about a month ago (http://blogs.msdn.co...uture-of-c.aspx) that supports variadic templates and few more nice features of C++11. They haven't yet updated Intellisense so its a bit weird because you will get syntax error in some places but it will compile. I used it in my main project for a while and didn't encounter any errors.

I'm not sure when these changes will be incorporated into main version but lets hope it will be soon
[/quote]

Thanks! =D

Worth noting, though, that the standard library is NOT updated with this CTP. This means that the following won't work:
 std::vector< int > my_ints = {1, 2, 3, 4, 5}; // won't compile // Neither will this... for(auto i: {1, 2, 3, 4, 5}) { std::cout << i << ' '; } 

since that relies on library features... Still, getting closer!! At least now I can begin prep-ing my g++4.7 projects for MSVC a little at a time

##### Share on other sites

[quote name='noizex' timestamp='1354041989' post='5004608']
[quote name='BigDaveDev' timestamp='1353870914' post='5003980']
-snip -

FYI, Microsoft released CTP about a month ago (http://blogs.msdn.co...uture-of-c.aspx) that supports variadic templates and few more nice features of C++11. They haven't yet updated Intellisense so its a bit weird because you will get syntax error in some places but it will compile. I used it in my main project for a while and didn't encounter any errors.

I'm not sure when these changes will be incorporated into main version but lets hope it will be soon
[/quote]

Thanks! =D

Worth noting, though, that the standard library is NOT updated with this CTP. This means that the following won't work:
 std::vector< int > my_ints = {1, 2, 3, 4, 5}; // won't compile // Neither will this... for(auto i: {1, 2, 3, 4, 5}) { std::cout << i << ' '; } 

since that relies on library features... Still, getting closer!! At least now I can begin prep-ing my g++4.7 projects for MSVC a little at a time
[/quote]

Yeah they clearly stated that std containers were not updated, but will be for the final release. Its still worth it, just for variadic templates. I rewrote some crazy factory code that had like 200 lines of code + weird macro magic to support variable number of constructor parameters into something that takes one screen of clean code without any macros

##### Share on other sites
Why would you even want to do this? What's wrong with the MSVC compiler provided with VS2012?
One valid reason would be that C++11 support in MSVC (even CTP) is very meager compared to its competitors.

Though I somewhat agree with you insofar as C++98 already has a lot to swallow for a beginner, and seeing how hardly any project uses C++11 features, it is probably wise to learn a standard that "works" first. On the other hand C++11 is really a lot easier in many respects, so if you care mostly for your own projects, it may be a viable option to learn the "proper thing" right away.
After roughly two years of on/off use and a year of exclusively using what's supported in C++11, I can hardly imagine going back (at least voluntarily!) to a compiler or language version that doesn't have auto, lambda, delegating constructors, variadic templates, template typedefs, or range based loops. Some C++11 features may be debatable, but most of it is just... awesome.

There is no "codeblocks compiler", did you mean gcc? If so, it does not exist as such under Windows, but you can use MinGW which is a POSIX wrapper to run gcc on windows.
Allow me a small, admittedly pedantic, objection: There is a "Code::Blocks compiler" insofar as the convenience package that most people use is the one that has GCC-MinGW bundled. Or at least, this just looks like "the Code::Blocks compiler" to the casual observer.

Also, note that MinGW is very much not a POSIX wrapper. Cygwin is such a thing, but MinGW states that they explicitly try not to be Cygwin, but to provide a more or less minimal wrapper around MSVCRT.

##### Share on other sites

Also, note that MinGW is very much not a POSIX wrapper. Cygwin is such a thing, but MinGW states that they explicitly try not to be Cygwin, but to provide a more or less minimal wrapper around MSVCRT.

Thanks, I believe I confused the two!

##### Share on other sites

One valid reason would be that C++11 support in MSVC (even CTP) is very meager compared to its competitors.

Though I somewhat agree with you insofar as C++98 already has a lot to swallow for a beginner, and seeing how hardly any project uses C++11 features, it is probably wise to learn a standard that "works" first. On the other hand C++11 is really a lot easier in many respects, so if you care mostly for your own projects, it may be a viable option to learn the "proper thing" right away.
After roughly two years of on/off use and a year of exclusively using what's supported in C++11, I can hardly imagine going back (at least voluntarily!) to a compiler or language version that doesn't have auto, lambda, delegating constructors, variadic templates, template typedefs, or range based loops. Some C++11 features may be debatable, but most of it is just... awesome.
VS2010 already had auto and lambda. VS2012 has range based loops (along with a big bunch of other stuff). The only missing thing I think would be important for a newbie is uniform initialization, and basic support for that is already in the update release (though to really make use of it, they still have to fix standard library containers to support it). You aren't giving up much by using the VS compiler anymore.

##### Share on other sites

One valid reason would be that C++11 support in MSVC (even CTP) is very meager compared to its competitors.

Though I somewhat agree with you insofar as C++98 already has a lot to swallow for a beginner, and seeing how hardly any project uses C++11 features, it is probably wise to learn a standard that "works" first. On the other hand C++11 is really a lot easier in many respects, so if you care mostly for your own projects, it may be a viable option to learn the "proper thing" right away.
After roughly two years of on/off use and a year of exclusively using what's supported in C++11, I can hardly imagine going back (at least voluntarily!) to a compiler or language version that doesn't have auto, lambda, delegating constructors, variadic templates, template typedefs, or range based loops. Some C++11 features may be debatable, but most of it is just... awesome.

Agreed, C++ 11 is awesome and I've been using its features extensively as well. The lack of full C++11 support in VS2012 is frustrating at some times (especially when it comes to variadic templates) but it's not a deal-breaker to me.
The OP however is, if I remember correctly, a relatively young person who hasn't done any or at least not much programming at all. He will be writing very simple programs in the beginning and definitely won't be needing any 'fancy' C++11 features which aren't supported by VS2012 yet at all for quite some time.
Visual Studio is a good choice as a beginner IDE since it has a lot of features which can make a programmer's life a lot easier, so in my opinion it would be a much better idea for the OP to work in a more friendly environment while sacrificing some compiler features he won't be needing anytime soon, instead of letting him use an environment that's maybe worse for beginners just so he can have more C++11 support. Once he's at the point where he's comfortable with C++ and programming in general there will probably be an updated version of MSVC available with better C++11 support, or if that's not the case he will be comfortable enough with the language to switch compilers and IDEs without any trouble.