mardi 1 novembre 2016

std::setw seems not to work when std::boolapha is applied

I've the following snippet of code:

std::ofstream file("...");

...
file.setf(std::ios::boolalpha);
file << std::setw(28);

file << p.second << "\n";
...

Applying file.setf(std::ios::boolalpha) makes file << std::setw(28); have no effect. How can I output boolean values to a file as strings "true" and "false" instead of simply outputting 0 and 1.

This actually seems not to work only for the boolean values (i.e. when p.second is a boolean), i.e. when p.second is not a boolean, std::setw(28) has effect and the corresponding width is applied.

Aucun commentaire:

Enregistrer un commentaire