The problem in this is that the program accepts a string with spaces only for the first input and not for the rest of the inputs. It seems that getline only works for the first input.
How can you make the vector store string with spaces (as elements of the vector)?
Eg:
Enter string:Harry Potter
Anymore(y/n):y
Enter string:
Anymore(y/n):y //The cursor comes here directly when y is input
Enter string:
Anymore(y/n):Superman //When you try to enter a string
//The program abruptly ends
#include<iostream>
#include<vector>
using namespace std;
int main()
{
string n;
vector<string> a;
char ch='y';
vector<string>::iterator i;
while(ch=='y'||ch=='Y')
{
cout<<"\nEnter string:";
getline(cin,n);
a.push_back(n);
cout<<"\nAnymore(y/n):";
cin>>ch;
}
for(i=a.begin();i!=a.end();++i)
cout<<*i<<"\n";
cin.get();
cin.get();
return 1;
}