cin>>
just takes the word until it encounters \0
cin.getline(name of string, string size)
takes the words until it encounters \n
\0
- Null character, it is there in every string of continues letters.
\n
- New line character, it is there when a line ends, (a line consists generally of 80 characters).
So, in your code you have used cin>>
which makes your program to only take a single word and not more than that.
Try using cin.getline(name of string, size of string)
instead which will make your code work accordingly.