Boolalpha question

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;
    }
The answer should be clear if you look at what getf() returns:
http://www.cplusplus.com/reference/iostream/ios_base/setf/
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
It is the return value of cout.setf( ios::boolalpha ). You should use instead std::boolalpha by means of including header <iomanip>
Yeah you are right, thanks
Topic archived. No new replies allowed.