Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7754077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:13:02+00:00 2026-06-01T12:13:02+00:00

Is there a (clean) way to manipulate some text from std::cin before inserting it

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:13:03+00:00Added an answer on June 1, 2026 at 12:13 pm

    (Non-extended) manipulators usually only set flags and data which the extractors afterwards read and react to. (That is what xalloc, iword, and pword are for.) What you could, obviously, do, is to write something analogous to std::get_money:

    struct uppercasify {
      uppercasify(std::string &s) : ref(s) {}
      uppercasify(const uppercasify &other) : ref(other.ref) {}
      std::string &ref;
    }
    std::istream &operator>>(std::istream &is, uppercasify uc) { // or &&uc in C++11
      is >> uc.ref;
      boost::to_upper(uc.ref);
      return is;
    }
    
    cin >> setw(80) >> uppercasify(mystring);
    

    Alternatively, cin >> uppercase could return not a reference to cin, but an instantiation of some (template) wrapper class uppercase_istream, with the corresponding overload for operator>>. 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 imbue a 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there some clean and elegant way to execute my code right after a
Is there a recommended way of using Django to clean an input string without
Is there any clean way to get a PropertyDescriptor from an expression tree? I
Is there a clean way to combine the SQL below into 1 statement? The
I was wondering if there is a clean way of counting from 0 to
Is there a clean way of cloning a record in SQL that has an
Is there a clean way to extract the VBA from a spreadsheet and store
Is there a clean way to expose a WCF REST service that requires basic
Is there a clean way to get a string containing only allowed characters? for
Simple one here... is there a clean way of preventing a user from double-clicking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.