KartalKaan's blog

By KartalKaan, 11 years ago, In English

Hello! I've just started using stringstream's but I've encountered a problem. Why does this code print 0 ?

#include<iostream>
#include<sstream>
using namespace std;
int main()
{
	stringstream ss;
	int i;
	ss<<0;
	ss>>i;
	ss<<1;
	cout<<ss.str()<<endl;
	return 0;
}

Thanks in advance.

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
11 years ago, # |
  Vote: I like it +5 Vote: I do not like it

This should work

#include<iostream>
#include<sstream>
using namespace std;
int main()
{
    stringstream ss;
    int i;
    ss<<0<<' ';
    ss>>i;
    ss<<1;
    cout<<ss.str()<<endl;
    return 0;
}