0

How to convert a string x="172" into int??

26th Oct 2016, 3:41 AM
prasanth pra
prasanth pra - avatar
2 Answers
+ 4
here's an example: #include <cstdlib> char input_line[ 30 ]; int main() { cout << "Enter a number: "; cin.getline(input_line, 29);//29 is one less than input_line's 30, for the null character int x = atoi(input_line);//atoi() is a function in cstdlib that converts string to int cout << "Variable x is equal to " << x << endl; return 0; }
26th Oct 2016, 4:34 AM
Zeke Williams
Zeke Williams - avatar
- 2
Idk tbh
26th Oct 2016, 4:26 AM
gabe
gabe - avatar