std::string title case

Discussion in 'C++' started by pkirk25, Nov 8, 2006.

  1. pkirk25

    pkirk25 Guest

    string name;
    cin >> name;

    User enters "johnny appleseeD".

    How can I use transform to reformat this as "Johnny Appleseed"?

    Thanks in advance.
    pkirk25, Nov 8, 2006
    #1
    1. Advertising

  2. pkirk25

    mlimber Guest

    mlimber, Nov 8, 2006
    #2
    1. Advertising

  3. pkirk25 wrote:
    > string name;
    > cin >> name;
    >
    > User enters "johnny appleseeD".
    >
    > How can I use transform to reformat this as "Johnny Appleseed"?


    You can't, because >> breaks the input on each whitespace,
    i.e. name will only contain "johnny".

    - J.
    Jacek Dziedzic, Nov 8, 2006
    #3
  4. pkirk25

    pkirk25 Guest

    mlimber wrote:
    > pkirk25 wrote:
    > > string name;
    > > cin >> name;
    > >
    > > User enters "johnny appleseeD".
    > >
    > > How can I use transform to reformat this as "Johnny Appleseed"?

    >
    > Sounds like homework to me.
    >
    > http://parashift.com/c -faq-lite/how-to-post.html#faq-5.2
    >
    > Cheers! --M


    I'm 42 and long past homework. Thanks for taking the time to share you
    expertise.
    pkirk25, Nov 8, 2006
    #4
  5. pkirk25

    pkirk25 Guest

    Jacek Dziedzic wrote:
    > pkirk25 wrote:
    > > string name;
    > > cin >> name;
    > >
    > > User enters "johnny appleseeD".
    > >
    > > How can I use transform to reformat this as "Johnny Appleseed"?

    >
    > You can't, because >> breaks the input on each whitespace,
    > i.e. name will only contain "johnny".
    >
    > - J.


    I didn't know that. The actual phrases I need to reformat are in
    format "darkmoon faire-alliance" and I'd like to change them to
    "Darkmoon Faire: Alliance". The colon is easy but the correct use of
    transform is not.
    pkirk25, Nov 8, 2006
    #5
  6. pkirk25

    Nate Barney Guest

    pkirk25 wrote:
    > The actual phrases I need to reformat are in format "darkmoon
    > faire-alliance" and I'd like to change them to "Darkmoon Faire:
    > Alliance". The colon is easy but the correct use of transform is
    > not.


    I probably wouldn't use std::transform for that. Take a look at boost
    (http://www.boost.org/libs/libraries.htm#String), particularly its regex
    library, and see if that might suit your needs.

    Nate
    Nate Barney, Nov 8, 2006
    #6
  7. pkirk25

    Jim Langston Guest

    "pkirk25" <> wrote in message
    news:...
    > string name;
    > cin >> name;
    >
    > User enters "johnny appleseeD".
    >
    > How can I use transform to reformat this as "Johnny Appleseed"?
    >
    > Thanks in advance.


    I would probably write my own function to do the convertion, I don't think
    transform would do it.
    Jim Langston, Nov 9, 2006
    #7
  8. pkirk25

    pkirk25 Guest

    Jim Langston wrote:
    > "pkirk25" <> wrote in message
    > news:...
    > > string name;
    > > cin >> name;
    > >
    > > User enters "johnny appleseeD".
    > >
    > > How can I use transform to reformat this as "Johnny Appleseed"?
    > >
    > > Thanks in advance.

    >
    > I would probably write my own function to do the convertion, I don't think
    > transform would do it.


    Easy enough - thanks.
    pkirk25, Nov 9, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Klemt
    Replies:
    1
    Views:
    436
    Steve C. Orr, MCSD
    Aug 10, 2003
  2. Peter Jansson
    Replies:
    5
    Views:
    6,263
    Ivan Vecerina
    Mar 17, 2005
  3. Fei Liu
    Replies:
    9
    Views:
    431
  4. Jeffrey Walton
    Replies:
    10
    Views:
    928
    Mathias Gaunard
    Nov 26, 2006
  5. Guest
    Replies:
    1
    Views:
    663
    Ken Cox [Microsoft MVP]
    Dec 25, 2004
Loading...

Share This Page