Change the compiler of c++ 11
Alternatively you can pause your program at the end using something like std::cin.get(); or getchar();
Cheers!
Cheers!
If this is a windows only application you can add the following line at the bottom of the main
Otherwise should work on any system
stytem( "pause" );
Otherwise should work on any system
std::cout << "press the enter key to continue" << std::endl;
char c;
std::cin >> c;
I really can't recommend against
enough. Especially when you can have highly portable functions available to you in the standard library.
I prefer to use something like:
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.
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.
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.
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
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 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.
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
[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.
It can be downloaded from here: http://www.microsoft...s.aspx?id=35515
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement