hey I want to input a string that contain spaces such as "My name is Shankhs";
i initialized a string str;
then cin>>str;
but str is not taking words after spaces as if spaces are acting as a delimiter...
i tried gets,getline but they does not seem to work for string!!!
So guys what should I do to make string take words after spaces???
(P.S. I have to work with string no char [] or char * please)
Thanx for your concern

hey I want to input a string that contain spaces such as "My name is Shankhs";
i initialized a string str;
then cin>>str;
but str is not taking words after spaces as if spaces are acting as a delimiter...
i tried gets,getline but they does not seem to work for string!!!
So guys what should I do to make string take words after spaces???
(P.S. I have to work with string no char [] or char * please)
Thanx for your concern

getline should work fine. Check out the example on this link. Type in a first and last name with a space in between at the prompt and it will read in the whole string (first + space + last). Spaces are indeed delimiters when you use >>.
http://www.cplusplus.com/reference/string/getline.html

thanx i implemented getline wrong so i was getting wrong answer thak you very much

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.