string to integer

hi,
can anyone help me with the use of stoi function.
i am getting the following error message-"test.cpp|8|error: 'nullptr' was not declared in this scope|""test.cpp|8|error: 'stoi' was not declared in this scope"

1
2
3
4
5
6
7
8
9
10
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int sum=stoi(s,nullptr,10);
    cout<<sum;
}
#include <cstddef>
#include <cstdlib>
#include <cstring>

try this :D
Make sure your compiler supports C++11 and that it is enabled. With GCC/MinGW you enable C++11 features by passing the -std=c++11 flag.
Works fine for me. What could be the issue is that nullptr is a C++11 keyword. Do you have C++11 support for whichever compiler that you are using?
adding c++11 support removed the nullptr error but stoi is still not recognised :(

please help,
Thanks in advance.
What compiler and what version do you use?
mingw 4.7.1(32-bit)
Last edited on
Unfortunately it looks like it's a problem with MinGW (not sure if this is fixed in later versions).
http://stackoverflow.com/questions/16132176/problems-with-stdstoi-not-working-on-mingw-gcc-4-7-2
Thank you!!
the patches made it work.
Topic archived. No new replies allowed.