This is an academic question.
sdt::mutex m;
typedef std::lock_guard<std::mutex> G;
void thread1(){
G g(m);
std::cout << std::setw(9);
std::cout << 3.14;
std::cout << std::endl;
}
void thread2(){
G g(m);
std::cout << std::setw(7);
std::cout << 3.14;
std::cout << std::endl;
}
My problem is that the formatting is bound to the output stream, so I need to set all the formatting options ever invented on my thread if I want to be sure about the output I produce. Which will or will not work next year.
- Is there any way to reset formatting to default without setting everything by hand?
- If not, what are the good workarounds?
- For example should I create and keep an
std::ostringstream
locally on my thread and writeoss.str()
tostd::cout
?
- For example should I create and keep an