std::ios is a typedef for std::basic_ios<char> which is a class that is publicly derived from std::ios_base, which is a class that has a public static member constant called "left"
You could have written std::cout << std::setiosflags(std::ios_base::left); for the same effect, or just std::cout << std::left; (there is a slight difference in that setiosflags resets all flags, while std::left only affects the adjustment flags)
As for the return type, it's just low-level machinery behind the I/O manipulators: those manipulators that take arguments (like setw or this setiosflags) are functions that return objects of unspecified type that have operator<< or operator>> overloads to apply the changes to the stream.
I didn't phrase that right, std::setiosflags() can set all formatting flags, e.g. hex, uppercase, and left at once. std::left/std::right/std::internal only affect adjustments.
std::left is an I/O manipulator that you can use instead of the much longer (and potentially ambiguous) std::setiosflags(std::ios::left). Like all I/O manipulators, it's a template function.
Simply put, yes. To be precise, it changes the field with value in the stream object, and most I/O operators change it back to zero. The full list of width-resetting operations is here: http://en.cppreference.com/w/cpp/io/manip/setw
A bitmask is a pattern of bits. A bitmask can be used to set, check or clear a bit pattern depending on which bitwise manipulation is used. The smallest representation we can manipulate that can be used to indicate true or false (1 or 0) is a bit, so a bit may be referred to as a flag.
The following program checks to see which bits are set in an unsigned int. It's pretty basic and I would encourage you to check out the bitwise operators and play around with this before you ask further questions.
#include <limits>
#include <iostream>
class Binary
{
public:
Binary(unsigned value) : _value(value) {}
operatorunsigned() { return _value ; }
private:
unsigned _value ;
};
std::ostream& operator<<(std::ostream& os, Binary b)
{
unsigned bitmask = 1u << (std::numeric_limits<unsigned>::digits-1u) ;
while ( bitmask )
{
os << ((b & bitmask) != 0) ;
bitmask >>= 1 ;
}
return os ;
}
int main()
{
unsigned n ;
while ( (std::cout << "Enter a number: ") && (std::cin >> n) )
std::cout << Binary(n) << '\n' ;
}
Enter a number: 2
00000000000000000000000000000010
Enter a number: 4
00000000000000000000000000000100
Enter a number: 8
00000000000000000000000000001000
Enter a number: 6
00000000000000000000000000000110
Enter a number: 12
00000000000000000000000000001100
Enter a number: 14
00000000000000000000000000001110
Enter a number: 15
00000000000000000000000000001111
Enter a number: 16
00000000000000000000000000010000
Enter a number: