3

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

Boris
  • 805
  • 1
  • 8
  • 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
  • 30,259
  • 8
  • 73
  • 100
1

I would prefer to use sstream.

erip
  • 16,374
  • 11
  • 66
  • 121
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
  • 67,789
  • 12
  • 98
  • 136