Sign in to follow this  
Sugavanas

Change the compiler of c++ 11

Recommended Posts

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,
[CODE]
#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;

}
[/CODE]

Share this post


Link to post
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 this post


Link to post
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 this post


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

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

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 this post


Link to post
Share on other sites
[quote name='BigDaveDev' timestamp='1353870914' post='5003980']
I really can't recommend [b]against [/b]
[CODE]
system("pause");
[/CODE]
enough. Especially when you can have highly portable functions available to you in the standard library.

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

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.
[/quote]

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.

It can be downloaded from here: http://www.microsoft.com/en-us/download/details.aspx?id=35515

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

Share this post


Link to post
Share on other sites
[quote name='noizex' timestamp='1354041989' post='5004608']
that supports variadic templates and few more nice features of C++11.
[/quote]

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 this post


Link to post
Share on other sites
[quote name='brx' timestamp='1354051093' post='5004675']
[quote name='noizex' timestamp='1354041989' post='5004608']
that supports variadic templates and few more nice features of C++11.
[/quote]

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 this post


Link to post
Share on other sites
[url=http://www.microsoft.com/visualstudio/eng/visual-studio-update]The official Update 1[/url] was just released yesterday. It's not a preview anymore.

Share this post


Link to post
Share on other sites
[quote name='SiCrane' timestamp='1354058712' post='5004734']
[url="http://www.microsoft.com/visualstudio/eng/visual-studio-update"]The official Update 1[/url] was just released yesterday. It's not a preview anymore.
[/quote]

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

Share this post


Link to post
Share on other sites
[quote name='noizex' timestamp='1354041989' post='5004608']
[quote name='BigDaveDev' timestamp='1353870914' post='5003980']
-snip -
[/quote]

FYI, Microsoft released CTP about a month ago ([url="http://blogs.msdn.com/b/vcblog/archive/2012/11/02/visual-c-c-11-and-the-future-of-c.aspx"]http://blogs.msdn.co...uture-of-c.aspx[/url]) 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.

It can be downloaded from here: [url="http://www.microsoft.com/en-us/download/details.aspx?id=35515"]http://www.microsoft...s.aspx?id=35515[/url]

I'm not sure when these changes will be incorporated into main version but lets hope it will be soon [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
[/quote]

Thanks! =D

Worth noting, though, that the standard library is NOT updated with this CTP. This means that the following won't work:
[CODE]
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 << ' ';
}
[/CODE]

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 this post


Link to post
Share on other sites
[quote name='BigDaveDev' timestamp='1354096900' post='5004906']
[quote name='noizex' timestamp='1354041989' post='5004608']
[quote name='BigDaveDev' timestamp='1353870914' post='5003980']
-snip -
[/quote]

FYI, Microsoft released CTP about a month ago ([url="http://blogs.msdn.com/b/vcblog/archive/2012/11/02/visual-c-c-11-and-the-future-of-c.aspx"]http://blogs.msdn.co...uture-of-c.aspx[/url]) 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.

It can be downloaded from here: [url="http://www.microsoft.com/en-us/download/details.aspx?id=35515"]http://www.microsoft...s.aspx?id=35515[/url]

I'm not sure when these changes will be incorporated into main version but lets hope it will be soon [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
[/quote]

Thanks! =D

Worth noting, though, that the standard library is NOT updated with this CTP. This means that the following won't work:
[CODE]
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 << ' ';
}
[/CODE]

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 this post


Link to post
Share on other sites
[quote name='Radikalizm' timestamp='1353669530' post='5003446']Why would you even want to do this? What's wrong with the MSVC compiler provided with VS2012?[/quote]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.

[quote name='Bacterius' timestamp='1353669683' post='5003447']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.[/quote]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 [i]not [/i]a POSIX wrapper. Cygwin is such a thing, but MinGW states that they explicitly try [i]not to be Cygwin, [/i]but to provide a more or less minimal wrapper around MSVCRT.

Share this post


Link to post
Share on other sites
[quote name='samoth' timestamp='1354101721' post='5004926']
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.
[/quote]
Thanks, I believe I confused the two!

Share this post


Link to post
Share on other sites
[quote name='samoth' timestamp='1354101721' post='5004926']
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.
[/quote]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 this post


Link to post
Share on other sites
[quote name='samoth' timestamp='1354101721' post='5004926']
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.
[/quote]

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this