how to differentiate 1 word or much than 1 word

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • odavilar
    New Member
    • Mar 2007
    • 3

    how to differentiate 1 word or much than 1 word

    hi, i'm trying to do this:

    Code:
    string x;
    cin>>x;
    
    if (x is one word){
    something
    }else{
    something
    }
    how can i differentiate between a word or a phrase.

    thanks for your help
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    is a word delimited by space characters? if so
    Code:
    string x;
    cin>>x;
    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.cppreferenc e.com/cppstring/getline.html

    you can then see if there is a space charcater in the string using find()
    http://www.cppreferenc e.com/cppstring/index.html

    Comment

    Working...