0

Possible Duplicates:
How to convert a number to string and vice versa in C++
c++ - convert pointer string to integer

Is there a way to convert a string into an integer parameter without any big algorithms?

string = "100";

integerFunction(int string);

I've tried atoi functions and tried to manually convert each number over with the string[count] - 48 way but it needs to be in a way where the number of digits don't become a problem with this. Any suggestions or algorithms out there that can help? I really appreciate it.

1
  • Why would the number of digits be a problem? Commented Jul 16, 2011 at 19:50

1 Answer 1

0

Like this:

int StringToInt( const std::string & str )
{
  std::stringstream ss(str);
  int res = 0;
  ss >> res;
  return res
}
Sign up to request clarification or add additional context in comments.

2 Comments

Why not use the stringstream constructor :P std::stringstream ss(str);
What advantage does this have over calling strtol, exactly?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.