1

I don't understand why the stoi function from < string > is available in Visual Studio 2010 ( Platform Toolset = v100 ) since from documentation says that is a C++11 feature.

Could somebody please help me understand this ?

I would like to use it with GCC 4.4.7 as well .... this is my original intent.

cristian
  • 518
  • 5
  • 20

4 Answers4

2

C++11 was a draft way before 2011. Since stoi() was going to make it into the standard many compilers already added it before C++11 was finalized. Using C++11 features before C++11 was finalized was experimental as things could change once the standard was ratified

Running

#include <iostream>
#include <string>
int main()
{
    int foo = std::stoi("5");
}

On godbolt.org with GCC 4.4.7 and -std=c++0x does compile so it looks like you are set to use it.

Live Example

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
  • Thank you @Nathan for explanation. So, stoi () it's available by default in Visual Studio 2010 ? Not need to make any specification in the project properties ? ( or other settings ). On the other hand with GCC I need to specify `-std=c++0x` to the compiler – cristian Oct 29 '15 at 12:41
  • 1
    @cristian Correct you do not need to specify the standard type in MSVS([source](http://stackoverflow.com/questions/19857263/how-to-activate-c11-standard-in-visual-studio-2010)). With gcc you do need to otherwise it default to C++03 – NathanOliver Oct 29 '15 at 12:43
  • Nathan, a followup question please. Specifying -std=c++0x is exactly the same with specifying -std=c++11 ? Has the same effect ? – cristian Oct 29 '15 at 14:03
  • @cristian at least on godbolt `-std=c++11` will fail with gcc 4.4.7 – NathanOliver Oct 29 '15 at 14:05
  • 1
    @cristian see this for when the change happened: http://stackoverflow.com/questions/16256586/how-to-enable-c11-on-later-versions-of-gcc – NathanOliver Oct 29 '15 at 14:08
1

Usually the Standard is discussed long before its final version will be adopted. During the discussion such documents like Working Draft of the Standard are published.

Sometimes it is clear enough before adopting the final revision of the Standard that some features will be included in the Standard because there is an unanimity among the members of the C++ Standards Committees.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
1

Compilers are allowed to provide extensions and library functions which aren't part of the C++ standard they're targeting. While VC++ 2010 doesn't comply fully with the C++11 standard, it does support certain features which are in C++11 and aren't in C++98, such as auto and static_assert.

There's a certain amount of risk involved in using "forward-compatible" features like this, because the draft of the standard the compiler writers targeted might have changed after the compiler was released, but C++11 was getting pretty stable by 2010, and the specification of stoi is almost certainly unchanged in the final standard from its implemention in VC++ 2010.

This page gives information on which VC++ versions support which C++11 features.

Sneftel
  • 40,271
  • 12
  • 71
  • 104
0

stoi is not a language feature (though VS2010 already had some minimal support for some features of c++11), but a library function. It just so happened that MS compiler team has already implemented the function in their implementation of the standard library by that time.

SingerOfTheFall
  • 29,228
  • 8
  • 68
  • 105