0

I have this simple function that parses a sentence into a vector of strings. It works, despite the fact I can't make it user driven and have to set src manually. No, this is not homework, I'm willfully creating a scripting language.

int main(){

string src, word;
vector<string> sent;

cout<<"enter script"<<endl;
cin>>src;

istringstream extract(src); ///extract word between space
cout<<src<<endl;

for(int i=0;i<30;i++){cout<<"_";}
cout<<endl;
while(extract >> word)
{
    sent.push_back(word); ///sentence vector
}
for(auto itr:sent)
    cout<<itr<<endl;

return 0;
}
  • Could you elucidate more on the issue you're having? I can't see immediately what the question is without running the source you have provided. Are you getting some form of error? Are you looking to make this more user-driven, as you describe it? – Gareth Pulham Apr 17 '17 at 00:41
  • I should of said, when I enter the sentence in cin>>src; First word is printed. When string src is pre-declared, it prints the words sequentially as needed. –  Apr 17 '17 at 00:44
  • Correct, this fixed it cout<<"Enter Script:"< –  Apr 17 '17 at 00:55

0 Answers0