0

How to use stoi?

I want to use a switch statement in C++ to check for user input, however, the input I want the switch to check is a string. I've read that by converting strings into integers (e.g. by using stoi) it is possible to use a switch statement to perform this task. Can someone show me an example of a conversion string -> integer done with stoi?

23rd Jan 2017, 6:39 PM
NNNicomedes
NNNicomedes - avatar
2 ответов
+ 3
u can use atoi and its the same, string to int string x = "10" int number = atoi(x.c_str())
23rd Jan 2017, 7:28 PM
Kawaii
Kawaii - avatar
+ 1
@n3twork which header file should i be including for atoi function. [edit] i got it. btw thanks for your answer.
24th Jan 2017, 3:22 AM
Rishabh Agrawal
Rishabh Agrawal - avatar