Originally Posted by
tabstop
Both gcc and visual studio give 1098.99 with that code.
Yet the input was "$1,098.98".
You forgot one step: actually erasing unused characters from the end of the string:
Code:
number.erase(std::remove(number.begin(),number.end(),','));
By the way, algorithms work on char arrays too:
Code:
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
int main()
{
char number[] = "$1,098.98";
*std::remove(number, number + strlen(number), ',') = '\0';
std::stringstream ss(number);
char dollar;
float value;
ss >> dollar >> value;
std::cout << value << std::endl;
return 0;
}