Ah, after I read carefully about stringstream. I have some code below:
//Note: PROBLEM mean I don't want like that, not something's wrong :)Code:int main(){
//string to Int
/* ******************************************** */
stringstream ss;
printf("FIRST TEST\n");
string strNum;
cin>>strNum;
ss<<strNum;
int a;
ss>>a;
a=a+1;
cout<<a<<endl; //NO PROBLEM HERE
//int to String
/* ******************************************* */
printf("SECOND TEST\n");
int num;
cin>>num;
ss<<num;
string str;
ss>>str;
str=str+" IS A NUMBER";
cout<<str<<endl; //PROBLEM: it just print "IS A NUMBER"
/* ****************************************** */
printf("THIRD TEST\n");
stringstream ss_2; string str_2;
cin>>num;
ss_2<<num;
ss_2>>str_2;
str_2=str_2+" IS A NUMBER";
cout<<str_2<<endl; //NORMAL AGAIN: it will print: "<num> IS A NUMBER"
/* ****************** */
return 0;
}
Uhm, in above code, at second test, if I use ss stringstream again, ss>>str will not put flow in ss into str. and the problem will be solved if I use another variable(example: ss_2). So, who can explain for me please :)
thanks :)