strtol() is the only way?
I'm trying to grab a C++ style string and fill a vector<unsigned int> with the same size as the string has characters. Each character on the string is a number from 0 to 9. As such the vector will have ints ranging from 0 to 9.
Follows a piece of the code with a literal string for testing purposes.
Code:
int strto_int (const string &str) {
const char *pstr = str.c_str();
char *pend;
return static_cast<int>( strtol(pstr, &pend, 0) );
}
int main()
{
string frame = "123423544126673467372411345223672338990";
vector<unsigned int> vframe;
for (string::size_type i = 0; i != frame.size(); ++i)
vframe.push_back( strto_int(frame.substr(i, 1)) );
}
My question relates to strtol(). I couldn't find any other way to convert. It seems to me though excessive to have to convert a C++-style string to a C-style string because I can only use C-style function to do some work on that C++ string. Is strtol() really the only way to convert? Or am I missing something on the STL?