Using stringstream to convert numeric types to strings
In the following code, I'm trying to figure out why when I output the string "data" it's empty:
Code:
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
int main()
{
string data;
stringstream outString(data);
int num = 50;
outString<<num;
cout<<data<<endl;
return 0;
}
My book says the parameter to the stringstream constructor is a reference so write operations for stringstream objects act directly on the string object(e.g. data):
stringstream outString(data);