0

How to convert string to integer in c++

string number_str = "1"; and i want to convert the number_str to integer

26th Oct 2017, 12:19 PM
Tanfirul Roibafi Muhammad
Tanfirul Roibafi Muhammad - avatar
3 Réponses
+ 4
You may use this Function, convert: #include <sstream> int convert(string d) { int var; stringstream ss(d); ss>>var; return var; } int main() { cout<<convert("1"); } Also, there are standard string conversion functions stoi, stol, stof etc for conversion of string to int, long and float respectively. You may use those if you don't wish to define your own function.
26th Oct 2017, 12:45 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 4
26th Oct 2017, 12:48 PM
Andrew
Andrew - avatar