M
Michael Coley
Hi, I've wrote this function which should add a comma for every 3
digits in a number (so that it looks something like 5,000).
This is my function:
std::string formatNumber(int number)
{
// Convert the int to a string.
std::string numString = boost::lexical_cast<std::string>(number);
std::string::const_reverse_iterator i = numString.rbegin(), end =
numString.rend();
for (int j = 0; i != end; ++i, ++j)
{
// Add a comma every three places.
if (j < 3)
{
// ERROR HAPPENS ON THIS LINE BELOW.
i = numString.insert(i + 1, ',');
end = numString.rend();
j = 0;
}
}
return numString;
}
I get an error saying it cannot convert from reverse_iterator to
unsigned int. It looks to me as if it's trying to call the wrong
overloaded function, as I did a search on the method and I can indeed
pass an iterator and a char.
Can anybody tell me why this is failing?
Thanks in advance.
digits in a number (so that it looks something like 5,000).
This is my function:
std::string formatNumber(int number)
{
// Convert the int to a string.
std::string numString = boost::lexical_cast<std::string>(number);
std::string::const_reverse_iterator i = numString.rbegin(), end =
numString.rend();
for (int j = 0; i != end; ++i, ++j)
{
// Add a comma every three places.
if (j < 3)
{
// ERROR HAPPENS ON THIS LINE BELOW.
i = numString.insert(i + 1, ',');
end = numString.rend();
j = 0;
}
}
return numString;
}
I get an error saying it cannot convert from reverse_iterator to
unsigned int. It looks to me as if it's trying to call the wrong
overloaded function, as I did a search on the method and I can indeed
pass an iterator and a char.
Can anybody tell me why this is failing?
Thanks in advance.