cout in the code below stops outputting anything after I copy buffer from empty sstringstream to it.
I dont quite understand why it happens.
I'll appreciate if you could help explain this.
Is there a better way to check stringstream before using rdbuf?
I was going to try if(ss.tellp() != ios::beg) but it caused compiled time error.
Code:
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
int main()
{
stringstream ss;
cout << ss.rdbuf();
string s = "abcdefg";
cout << s; // nothing comes out on screen.
cout << "123"; // nothing.
}
Looks to me, like it interprets it as setting the buffer associated with it.. and when you use cout, you're writing to some random place in memory.. not the console.
2) My guess is that when the stringstream is empty, the
"cout << ss.rdbuf();" FAILS (not just outputs nothing).
Once the stream's state becomes bad, further use of the
stream fails.
3) If this is the case, clear couts internal flags.
hey this is my code.. the classes are returning correct values.. but look at the output!!!!! i cant fix it.. ive tried everything.. it works perfectly in visual studio but it messes up this way in unix. and since i have to submit this in unix i need help.
part of the code:
cout << setw(25)<<"Name" << setw(20)<< "Phone Number" << setw(15) << "Date of Birth" << endl << endl;
int i;
for (i = 0;(i<y);i++)
{
p = b[i];
cout << setw(25) << p.get_person().getLastName() + ", " + p.get_person().getFirstName() + " " + p.get_person().getMiddleName();
cout << setw(20) << p.getphone() ;
cout << p.get_date().getDayofweek() << ", ";
if (p.get_date().getMonth()==1)
cout << "January";
else if (p.get_date().getMonth() == 2)
cout << "February";
else if (p.get_date().getMonth()==3)
cout << "March";
else if (p.get_date().getMonth()==4)
cout << "April";
else if (p.get_date().getMonth()==5)
cout << "May";
else if (p.get_date().getMonth()==6)
cout << "June";
else if (p.get_date().getMonth()==7)
cout << "July";
else if (p.get_date().getMonth()==8)
cout << "August";
else if (p.get_date().getMonth()==9)
cout << "September";
else if (p.get_date().getMonth()==10)
cout << "October";
else if (p.get_date().getMonth()==11)
cout << "November";
else if (p.get_date().getMonth()==12)
cout << "December";
cout << " " << p.get_date().getDay() << ", " << p.get_date().getYear() << endl;
Bookmarks