By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,922 Members | 1,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,922 IT Pros & Developers. It's quick & easy.

how to differentiate 1 word or much than 1 word

P: 3
hi, i'm trying to do this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. string x;
  3. cin>>x;
  4.  
  5. if (x is one word){
  6. something
  7. }else{
  8. something
  9. }
  10.  
  11.  
how can i differentiate between a word or a phrase.

thanks for your help
Mar 24 '07 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 1,510
is a word delimited by space characters? if so
Expand|Select|Wrap|Line Numbers
  1. string x;
  2. cin>>x;
  3.  
reads up to the next whitespace (spaces and newlines) so you will always read words. If you wish to read a line of text use getline()
http://www.cppreference.com/cppstring/getline.html

you can then see if there is a space charcater in the string using find()
http://www.cppreference.com/cppstring/index.html
Mar 24 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.