samedi 31 mars 2018

cannot extract from stringstream after clearing

I would like to extract "World" from the stringstream parser after clearing it but the string strB is empty. Any suggestions on how I can fix this and why this is happening ?

int main()
{
        std::string strA;
        std::string strB;

        std::stringstream parser("Hello");
        parser >> strA;
        std::cout << strA;

        parser.clear();
        parser << "World";
        parser >> strB;
        std::cout << strB; // Why cant i extract from parser again ? ? Why is strB empty ?     
}

Aucun commentaire:

Enregistrer un commentaire