Boolalpha question
Aug 28, 2012 at 8:12pm UTC
I was practicing with string methods and I wanted empty() to return true or false instead of 1 and 0 so I used boolalpha but now it returns 4098false or 4098true, where did the 4098 came from? how to fix it?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
using namespace std;
int main()
{
string sentence;
getline(cin, sentence);
cout << cout.setf(ios::boolalpha) << sentence.empty() << endl;
cin.get();
return 0;
}
Aug 28, 2012 at 8:19pm UTC
Aug 28, 2012 at 8:21pm UTC
Nevermind I only had to do this
1 2
cout.setf(ios::boolalpha);
cout << sentence.empty() << endl;
But I would still like to know why the other method also printed 4098 if anyone knows :D
Aug 28, 2012 at 8:23pm UTC
It is the return value of cout.setf( ios::boolalpha ). You should use instead std::boolalpha by means of including header <iomanip>
Aug 28, 2012 at 8:27pm UTC
Yeah you are right, thanks
Topic archived. No new replies allowed.