Is there a (clean) way to manipulate some text from std::cin before inserting it into a std::string, so that the following would work:
cin >> setw(80) >> Uppercase >> mystring;
where mystring is std::string (I don’t want to use any wrappers for strings).
Uppercase is a manipulator. I think it needs to act on the Chars in the buffer directly (no matter what is considered uppercase rather than lowercase now). Such a manipulator seems difficult to implement in a clean way, as user-defined manipulators, as far as I know, are used to just change or mix some pre-determined format flags easily.
(Non-extended) manipulators usually only set flags and data which the extractors afterwards read and react to. (That is what
xalloc,iword, andpwordare for.) What you could, obviously, do, is to write something analogous tostd::get_money:Alternatively,
cin >> uppercasecould return not a reference tocin, but an instantiation of some (template) wrapper classuppercase_istream, with the corresponding overload foroperator>>. I don’t think having a manipulator modify the underlying stream buffer’s contents is a good idea.If you’re desperate enough, I guess you could also
imbuea hand-crafted locale resulting in uppercasing strings. I don’t think I’d let anything like that go through a code review, though – it’s simply just waiting to surprise and bite the next person working on the code.