f



std::stoi

I have been using stoi to convert string representation of numbers into int
since long. Only recently one such program of mine stopped working giving
following error:

string_int.cpp: In function 'int main(int, char**)':
string_int.cpp:29: error: 'stoi' is not a member of 'std'

Here is the code snippet:

    std::string newValStr = "777;
    int newValInt = 0;
    newValInt = std::stoi(newValStr);

I looked around internet and there doesn't seem to be any update on it. I am
compiling it using g++ on Redhat Linux 6.2 with following gcc version:

gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC)

Has anyone else also faced something similar?

thanks
KR


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
kiran
11/4/2015 6:56:28 AM
comp.lang.c++.moderated 10738 articles. 1 followers. allnor (8509) is leader. Post Follow

7 Replies
422 Views

Similar Articles

[PageSpeed] 46

On 11/04/2015 07:56 AM, kiran wrote:
> 
> I have been using stoi to convert string representation of numbers into int
> since long. Only recently one such program of mine stopped working giving
> following error:
> 
> string_int.cpp: In function 'int main(int, char**)':
> string_int.cpp:29: error: 'stoi' is not a member of 'std'
> 
> Here is the code snippet:
> 
>     std::string newValStr = "777;
>     int newValInt = 0;
>     newValInt = std::stoi(newValStr);
> 
> I looked around internet and there doesn't seem to be any update on it. I am
> compiling it using g++ on Redhat Linux 6.2 with following gcc version:
> 
> gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC)
> 
> Has anyone else also faced something similar?

stoi is not present in n1836.pdf, the oldest version of the C++ standard
that I have. It is present in n2723.pdf, the second oldest (2008-08-25)
and n3797.pdf, the lastest version I have (2013-10-13).

I didn't even know it existed till today, so I can't tell you anything
about what happened with it.
-- 
James Kuyper


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
James
11/5/2015 7:23:06 AM
> I have been using stoi to convert string representation of numbers
> into int since long. Only recently one such program of mine stopped
> working giving following error:
> 
> string_int.cpp: In function 'int main(int, char**)':
> string_int.cpp:29: error: 'stoi' is not a member of 'std'
> 
> Here is the code snippet:
> 
>     std::string newValStr = "777;
>     int newValInt = 0;
>     newValInt = std::stoi(newValStr);
> 
> I looked around internet and there doesn't seem to be any update on
> it. I am compiling it using g++ on Redhat Linux 6.2 with following
> gcc version:
> 
> gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC)
> 
> Has anyone else also faced something similar?

Do you have C++11 enabled when compiling? -std=c++11? Maybe you changed
your compiler flags and it's now missing.

std::stoi was added in C++11.
http://en.cppreference.com/w/cpp/string/basic_string/stol

Regards,
Frank


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Frank
11/5/2015 7:23:08 AM
On Wednesday, 4 November 2015 15:00:50 UTC+2, kiran  wrote:
> I have been using stoi to convert string representation of numbers into
int
> since long. 
>
> Only recently one such program of mine stopped working giving
> following error:
> 
> string_int.cpp: In function 'int main(int, char**)':
> string_int.cpp:29: error: 'stoi' is not a member of 'std'
> 
> Here is the code snippet:
> 
>     std::string newValStr = "777;
>     int newValInt = 0;
>     newValInt = std::stoi(newValStr);

It is not the code. That snippet should get some other parse errors
from compiler since it clearly contains only one instance of double
quotes ("). Prefer copy-pasting full code of real program.

> 
> I looked around internet and there doesn't seem to be any update on it. I
am
> compiling it using g++ on Redhat Linux 6.2 with following gcc version:
> 
> gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC)
> 
> Has anyone else also faced something similar?

Do you cave -std=gnu++0x or -std=c++0x option in command line?
'std::stoi' was added by C++11.


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
ISO
11/5/2015 7:23:13 AM
On Wed,  4 Nov 2015 06:56:28 CST, kiran
<kiran.tangeeda@googlemail.com> wrote:

>
>I have been using stoi to convert string representation of numbers into int
>since long. Only recently one such program of mine stopped working giving
>following error:
>
>string_int.cpp: In function 'int main(int, char**)':
>string_int.cpp:29: error: 'stoi' is not a member of 'std'
>
>Here is the code snippet:
>
>    std::string newValStr = "777;
>    int newValInt = 0;
>    newValInt = std::stoi(newValStr);
>
>I looked around internet and there doesn't seem to be any update on it. I
am
>compiling it using g++ on Redhat Linux 6.2 with following gcc version:
>
>gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC)
>
>Has anyone else also faced something similar?
>
>thanks
>KR

A search for "g++ std::stoi" turned up this:

http://stackoverflow.com/questions/14743904/stdstoi-missing-in-g-4-7-2

I tried your code (with the missing quote added after the 777) on FC
22 with g++ 5.1.1;  I saw the same problem, and I was able to make it
work with -std=c++11.

I don't know why it might have worked for you before.

Louis


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Louis
11/5/2015 7:24:41 AM
Em quarta-feira, 4 de novembro de 2015 11:00:50 UTC-2, kiran  escreveu:
> I have been using stoi to convert string representation of numbers into
int
> since long. Only recently one such program of mine stopped working giving
> following error:
> 
> string_int.cpp: In function 'int main(int, char**)':
> string_int.cpp:29: error: 'stoi' is not a member of 'std'
> 
> Here is the code snippet:
> 
>     std::string newValStr = "777;
>     int newValInt = 0;
>     newValInt = std::stoi(newValStr);
> 
> I looked around internet and there doesn't seem to be any update on it. I
am
> compiling it using g++ on Redhat Linux 6.2 with following gcc version:
> 
> gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC)
> 
> Has anyone else also faced something similar?
> 

Are you including the <string> header? End there is a missing " in the code.


Anyway, if you would like an advise, I'd recommend you to use istringstream
and operator >> in order to perform tihs conversion in a more C++ish way.

Best,
Elias.


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
ISO
11/5/2015 7:25:08 AM
On 05/11/2015 13:25, Elias Salom´┐Żo Helou Neto wrote:
>
> Em quarta-feira, 4 de novembro de 2015 11:00:50 UTC-2, kiran  escreveu:
>> I have been using stoi to convert string representation of numbers into
> int
>> since long. Only recently one such program of mine stopped working giving
>> following error:
>>
>> string_int.cpp: In function 'int main(int, char**)':
>> string_int.cpp:29: error: 'stoi' is not a member of 'std'
>>
>> Here is the code snippet:
>>
>>      std::string newValStr = "777;
>>      int newValInt = 0;
>>      newValInt = std::stoi(newValStr);
>>
>> I looked around internet and there doesn't seem to be any update on it. I
> am
>> compiling it using g++ on Redhat Linux 6.2 with following gcc version:
>>
>> gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC)
>>
>> Has anyone else also faced something similar?
>>
>
> Are you including the <string> header? End there is a missing " in the
code.
>
>
> Anyway, if you would like an advise, I'd recommend you to use
istringstream
> and operator >> in order to perform tihs conversion in a more C++ish way.
>
> Best,
> Elias.
>
>
:) Surely using the C++ Standard Library is the C++ way. I think, that 
as others have suggested, you need to check your compiler switches. Most 
compilers allow you to select which version of C++ you are using. You 
need C++ 11 or higher for stoi to be available.

Francis


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Francis
11/5/2015 12:25:21 PM
- The double quotes around 777, missing in the my post above, were indeed
present in the program.
- I included the <string> header file.
- As a workaround I did use stringstream in the meantime. 

The conclusion: My compiler flags were missing. Once I added -std=c++0x,
stoi is working good. 

Thank you all for the responses. I am able to get it working now. 

- Kiran


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
kiran
11/5/2015 3:36:07 PM
Reply:

Similar Artilces:

How to read an input text from keyboard by the std. lang. C?
Hello, how to read an input text from keyboard (on a console) by the standard languace C, please? I really need a tip about this question. TIA, Vinicius. What kind of input? Do you want to read a word? A sentence? A number? There's more than one way to get input from stdin, but for the most part you'll find yourself using fgets: #include <stdio.h> #include <stdlib.h> int main(void) { char buffer[BUFSIZ]; printf("Enter some text: "); fflush(stdout); if (fgets(buffer, sizeof buffer, stdin) == NULL) { fprintf(stderr, "Input error\n"); return EXIT_FAIL...

jython and C-c C-c
How do I get C-c C-c to work with jython? I have the jpython command set to jython, and I can start the interpreter with C-C ! and then use C-c C-c, but this is rather frustrating. If I try to use C-c C-c without first starting the interpreter in another window I get wrong type argument: sequencep, jpython Thanks, Dave Cook ...

Better C/C++ Than C/C++?
I am looking for a good systems programming language that can be used instead of C/C++. My qualifications for the language are: * mature compiler(s) that produce native-code binaries (for Windows) * open source - preferable, but not 100% necessary Thanks, Kevin "Kevin Albrecht" <kevin@albrecht.net> writes: > I am looking for a good systems programming language > that can be used instead of C/C++. My qualifications > for the language are: > > * mature compiler(s) that produce native-code > binaries (for Windows) Ocaml, D, cyclone, Eiffel, Beta >...

C as a Subset of C++ (or C++ as a superset of C)
Isn't it a lame use of human time and effort to maintain completely separate C and C++ standards? As in the words of Betty White about Facebook: "It seems like an incredible waste of time". Why don't the two standards groups get together and agree on a common specification for the ground which both standards cover? There would still be two separate standards, but they'd both be exactly the same for the common ground. The common ground document could be referred to by both standards instead of being maintained by both groups in individual efforts resulting in...

C/C++ in matlab and matlab in C/C++ ?
Is it possible to read C/C++ code in matlab and the other way around too? Hi, as long as C or C++ are written in text files you can edit them in the matlab editor. To see the special character of C or C++ coding language, in the editor go to menus: file>preferences>Edito/Debugger>language and on popup "Language" select "C/C++". This does not allow you to run the C/C++ code, just to view it i nicer way... regards, chris saneman <asdfsdf@asd.com> wrote in message <frl846 $f8i$2@news.net.uni-c.dk>... > Is it possible to read C/C...

C/C++ in MATALB or MATLAB in C/C++?
Hi I've been asking on the net how to use MEX properly so that I can use C/C++ in MATLAB, but information is not forthcoming. There seems to be a lot on using MATLAB in C/C++ but not the other way around. I understand Mathworks is trying very hard to sell the Matlab Compiler, but even so, why is it SO hard to get information about MEX? Or is it that I've missed something very fundamental, meaning that I'm struggling over something that is actually quite easy? Any thoughts and info would be great. Thanks BullDog BullDog wrote: > Hi > > I've been asking on the net ...

c------->c++ and c++------>c
We can write c program in turbo c++ editor.But reverse is not true why? i.e The program will not compile if u write c++ program in turbo c editor vim wrote: > We can write c program in turbo c++ editor.But reverse is not true why? > i.e The program will not compile if u write c++ program in turbo c > editor This isn't about C; this is about some editor. Why the fircone should /we/ know? Ask in a relevant group. [And /why/, in an editor specialised to some specific programming languages, would you expect it to compile a /different/ one? Would you expect turbo perl to compi...

slime C-c C-c annoyance
Does anyone have a good workaround for this problem other than: just be careful! When I've compiled a large package and slime has given me a *slime-compilation* buffer, I like to work through this buffer issue by issue, fixing the errors, warnings, etc. But If I ever press C-c C-c in the editor window while fixing an error, slime destroys the *(slime-compilation* buffer with the compilation output of C-c C-c. Jim Newton <jimka.issy@gmail.com> writes: > Does anyone have a good workaround for this problem other than: just be careful! > > When I've compiled a ...

C,, C++, Java, C#
I come from C,C++,Java and C#. What can SmallTalk do for me and for what cost? Regarding the Squeak thing, it's interesting though confusing. Is it an IDE? Why are the menus so wacky? "DM McGowan II" <nospam@nospam.net> wrote in message news:PLednX2vnLd11IncRVn-rA@comcast.com... > I come from C,C++,Java and C#. What can SmallTalk do for me ...? Ask not what Smalltalk can do for, but what can you do with Smalltalk. :-) In very few words, it significantly reduces time to market, while enhancig the development experience. This is because: 1. It...

C, C++ and C# Forums
Throne Software has opened up C, C++ and C# Forums at: http://www.thronesoftware.com/forum/ Join us! In article <1120963701.862698.160260@g14g2000cwa.googlegroups.com>, Throne Software <mail@thronesoftware.com> writes >Throne Software has opened up C, C++ and C# Forums at: > >http://www.thronesoftware.com/forum/ > >Join us! Why? The beauty of news groups is that they come to me I don't have to go to them. Also all the people who have been around a while know what they are doing and are here. I noticed that there are some C and C++ Forums on another system...

C, C++ and C# Forums
Throne Software has opened up C, C++ and C# Forums at: http://www.thronesoftware.com/forum/ Join us! Throne Software wrote: > Throne Software has opened up C, C++ and C# Forums at: > > http://www.thronesoftware.com/forum/ For all of your forums newsgroups already exist. > Join us! Why? Don't see any reason to support your marketing. ...

C, C++ and C# Forums
Throne Software has opened up C, C++ and C# Forums at: http://www.thronesoftware.com/forum/ Join us! ...

c,c++,obj-c
Of the 3 languages titled in this post is c++ older than obj-c ? Would someone experienced in C be able to dive right into C++ rather than obj-c ? Java is out for me now except applet programming I think I'm going to go with just C and C++. Bill Bill Cunningham wrote: > Of the 3 languages titled in this post is c++ older than obj-c ? Why does that matter? Do you want to use an old language? Try Fortran or LISP. > Would > someone experienced in C be able to dive right into C++ rather than > obj-c ? Not quite dive in, at least not into the OO parts of C++. ...

More about C and C++
Hello... I have wrote: >I will resume it like this: >On the criterias of "complexity" and "difficulty", the C and C++ >programming languages are more complex and difficult than Object >Pascal for example, so since they are more complex and difficult they >are likely to create something like a darwinian filter who don't let >the weaker humans among us humans to cross or to climb the social >ladder, this is why i think that C and C++ do participate to social >darwinism, this is why i say that C and C++ are bad. Josep...

Lang C
www.BrandonsMansion.com ...

Web resources about - std::stoi - comp.lang.c++.moderated

Resources last updated: 1/25/2016 1:15:36 AM