Di recente ho avuto un problema a crearne uno a stringstreamcausa del fatto che supponevo erroneamente che std::setw()avrebbe influenzato il flusso di stringhe per ogni inserimento, fino a quando non l'ho modificato esplicitamente. Tuttavia, è sempre non impostato dopo l'inserimento.
// With timestruct with value of 'Oct 7 9:04 AM'
std::stringstream ss;
ss.fill('0'); ss.setf(ios::right, ios::adjustfield);
ss << setw(2) << timestruct.tm_mday;
ss << timestruct.tm_hour;
ss << timestruct.tm_min;
std::string filingTime = ss.str(); // BAD: '0794'
Quindi, ho una serie di domande:
- Perché è
setw()così? - Ci sono altri manipolatori in questo modo?
- C'è una differenza nel comportamento tra
std::ios_base::width()estd::setw()? - C'è infine un riferimento online che documenta chiaramente questo comportamento? La documentazione del mio fornitore (MS Visual Studio 2005) non sembra mostrarlo chiaramente.