mercredi 3 juin 2015

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

My requirement described as below. I am reading a file in stringstream object which 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 I am trying to populate the value in variables i am getting "," also along with it. Can any one suggest so that I can store all these value in respective variable without ","

Just a sample code to help the 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

Aucun commentaire:

Enregistrer un commentaire