c++ - Can we change the default behavior of ">>" overloaded operator for stringstream object? -


my requirement described below. reading file in stringstream object contain

"neck_ap \ ul, 217.061, -40.782\n\ ur, 295.625, -40.782\n\ ll, 217.061, 39.194\n\ lr, 295.625, 39.194". 

when trying populate value in variables getting "," along it. can 1 suggest can store these value in respective variable without ","

just sample code situation:

int _tmain(int argc, _tchar* argv[]) {     char pause;     stringstream stream;     stream.str("neck_ap \ ul, 217.061, -40.782\n\ ur, 295.625, -40.782\n\ ll, 217.061, 39.194\n\ lr, 295.625, 39.194");      string value1,value2,value3,value4;      stream >> value1>>value2>>value3>>value4;     cout << value1<<value2<<value3<<value4<<endl;                 cin >> pause;     return 0; } 

output

nect_ap ul,217.061,-40.782

required output

nect_ap ul 217.061 -40.782

you need understand functions(or operators, etc.) (most of time) written job. operator >> has job of getting data stream place. that's job , should this. want do, write new function(or use existing one) later change value, way want it.

what want can achieved of standard library:

#include <algorithm> //some code... std::replace_if(value1.begin(), value1.end(), [](char x){return x == ',';}, ' '); 

and each value. alternatively, load 1 string, use function on string, , print contents. do? replace_if takes 4 arguments: container's beginning , end iterator(first 2 arguments), predicate function(i'm using called lambda expression, or anonymous function; can write separate function , provide name, no problem!), , new value. can translated "replace every character in string ' ', if meets predicate(in other words, colon).


Comments