3

In C++. What are the alternatives to Integer.parseInt() and String.valueOf() of Java in C++.

Boris
  • 785
  • 1
  • 7
  • 20

3 Answers3

8

For Integer.parseInt you can use std::stoi, std::istringstream, sscanf, atoi etc.

For String.valueOf() alternatives, you can std::ostringstream, sprintf, std::tostring etc.

Recommendations:
stoi and tostring
istringstream and ostringstream
atoi and sprintf

Mohit Jain
  • 29,859
  • 8
  • 70
  • 95
1

I would prefer to use sstream.

erip
  • 15,290
  • 10
  • 62
  • 113
0

You may use atoi c++ function.

int atoi (const char * str);

Convert string to integer Parses the C-string str interpreting its content as an integral number, which is returned as a value of type int.

Reference: http://www.cplusplus.com/reference/cstdlib/atoi/

Juned Ahsan
  • 66,028
  • 11
  • 91
  • 129