Saturday 15 March 2014

C++ How to cin a string into a vector and then display the inputs -



C++ How to cin a string into a vector and then display the inputs -

im little stuck on trying figure out how allow user come in in several strings , display strings when come in "*". help appreciated! thanks!

#include <iostream> #include <vector> #include <string> using namespace std; int main() { string input; cout<<"enter in shopping list. come in in * indicate done"<<endl; vector<string> shoppinglist(); while(cin>>input && input != *) { shoppinglist.push_back(input); } if(cin>>input == *) { write_vector(shoppinglist); } homecoming 0; }

there 2 things wrong in this:-

vector<string> shoppinglist(); //this treated function declaration...

this should be

vector<string> shoppinglist;

and then

if(cin>>input == *)

you should take input in string , compare "*"

c++ string vector cin

No comments:

Post a Comment