473,394 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

std::string title case

string name;
cin >name;

User enters "johnny appleseeD".

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

Thanks in advance.

Nov 8 '06 #1
7 4709
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/ho...t.html#faq-5.2

Cheers! --M

Nov 8 '06 #2
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.
Nov 8 '06 #3

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/ho...t.html#faq-5.2

Cheers! --M
I'm 42 and long past homework. Thanks for taking the time to share you
expertise.

Nov 8 '06 #4

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.

Nov 8 '06 #5
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
Nov 8 '06 #6
"pkirk25" <pk****@kirks.netwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
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.
Nov 9 '06 #7

Jim Langston wrote:
"pkirk25" <pk****@kirks.netwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
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.

Nov 9 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Espen Ruud Schultz | last post by:
Lets say I have a char pointer and an std::string. Is it possible to get a pointer to the std::string's "content" so that the char pointer can point to the same text? And vice versa; can I give...
10
by: Angus Leeming | last post by:
Hello, Could someone explain to me why the Standard conveners chose to typedef std::string rather than derive it from std::basic_string<char, ...>? The result of course is that it is...
2
by: Neil Zanella | last post by:
Hello, Consider the following program. There are two C style string stack variables and one C style string heap variable. The compiler may or may not optimize the space taken up by the two stack...
4
by: Jim Langston | last post by:
Is there any builtin lowercase std::string compare? Right now I'm doing this: if ( _stricmp( AmmoTypeText.c_str(), "GunBullet" ) == 0 ) AmmoType = Item_Ammo_GunBullet; Is there anything the...
10
by: mr_sorcerer | last post by:
Hi! I just found something interesting. I mean what do you think about this: char *p = 0; std::string str = p; Why std::string doesn't check null pointers?
5
by: probstm | last post by:
I am using a message handler class that implements amongst others: static void message ( std::string aHeader, std::string aMessage, int aTimeout = 0, MessageType aFlag = MSG_Information ); ...
11
by: Jacek Dziedzic | last post by:
Hi! I need a routine like: std::string nth_word(const std::string &s, unsigned int n) { // return n-th word from the string, n is 0-based // if 's' contains too few words, return "" //...
14
by: Mosfet | last post by:
Hi, what is the most efficient way of doing a case insensitive comparison ? I am trying to write a universal String class and I am stuck with the case insensitive part : TCHAR is a char in...
25
by: Bala2508 | last post by:
Hi, I have a C++ application that extensively uses std::string and std::ostringstream in somewhat similar manner as below std::string msgHeader; msgHeader = "<"; msgHeader += a; msgHeader...
11
by: tech | last post by:
Hi, I need a function to specify a match pattern including using wildcard characters as below to find chars in a std::string. The match pattern can contain the wildcard characters "*" and "?",...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.