std::string title case

P

pkirk25

string name;
cin >> name;

User enters "johnny appleseeD".

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

Thanks in advance.
 
J

Jacek Dziedzic

pkirk25 said:
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.
 
P

pkirk25

Jacek said:
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.
 
N

Nate Barney

pkirk25 said:
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
 
J

Jim Langston

pkirk25 said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top