jeudi 5 mai 2016

Weird behaviour of stringstream ?

I am not able to understand why after reaching the last word it doesn't output blank or null character or garbage value or anything else . Why >> doesn't has any impact whatsoever after finishing the string .

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
int main()
{
    stringstream ss("I am going to goa for");  // Used for breaking words
    string word; // To store individual words
    while (ss >> word)
        cout<<word<<"\n";
    ss >> word;
    cout<<word<<endl;
    ss >> word;
    cout<<word<<endl;
    ss >> word;
    cout<<word<<endl;
}

OUTPUT:

I am going to goa for for for for

Aucun commentaire:

Enregistrer un commentaire