Can someone explain to me why my output is this? And how would I correct my output?

Posted by user342231 on Stack Overflow See other posts from Stack Overflow or by user342231
Published on 2010-05-16T06:02:01Z Indexed on 2010/05/16 6:10 UTC
Read the original article Hit count: 231

Filed under:
|
|
|
|
/*  in this slice of code I get an output of
    bbb 55 66 77 88
    aaa
    the output I expect and want is
    bbb 55 66 77 88
    bbb
    because I reassign ss from log[0] to log[1]
    So my question is why is the output different from what I expect and how do I 
    change it to what I want?
*/    
      int w,x,y,z;
      stringstream ss (stringstream::in | stringstream::out);
      string word;
      string log[2];
      log[0]="aaa 11 22 33 44";
      log[1]="bbb 55 66 77 88";

      ss<<log[0];
      ss>>word;

      int k=0;
      ss>>w>>x>>y>>z;
      k++;

      ss<<log[k];
      cout<<log[k]<<endl;
      ss>>word;
      cout<<word<<endl;
      return 0;

© Stack Overflow or respective owner

Related posts about c++

Related posts about beginner