I need to save the words into my struct/class ...
and I thought if I used cin then it would just take the whole input as one word and I need to save each individual word ;
For example, if I wanted to save my name is apple
using cin, wouldn't my output be
mynameisapple
?I don't want that because that input is 4 words, not 1
#include <iostream>
#include <string>
#include <vector> //This is only for vector
usingnamespace std;
int main()
{
string s;
vector<string> v;
cout<<"Please enter some sentences below. A word '@@@' terminates the input.\n";
while (true)
{
cin >> s;
if (s=="@@@") break;
//Do whatever you want to do with string. In this case I'm adding it
//in vector
v.push_back(s);
}
cout << endl<<"The words you entered are"<<endl;
//Now show all the strings
vector<string>::iterator i;
for (i=v.begin();i!=v.end();i++)
cout << *i<<endl;
return 0;
}
Please enter some sentences below. A word '@@@' terminates the input.
Blah Blah I'm a Banana @@@
The words you entered are
Blah
Blah
I'm
a
Banana
Hey, of course I know how classes work and if your book doesn't explain then you can always look for help. And that's what Google is there for. Isn't it?? But I think there are a lot of tutorials on this site alone. Here, take a look at it.
As much as I'd love to learn about vectors, because my Prof hasn't covered it in class, I wouldn't be able to use it in my programming because my assignments have strict requirements as to what I can and cannot use. (Like, my last assignment I could use C-strings but this assignment I can only use strings)
So, learning about vectors would be useless until my prof covered them in class, if he even is going to --.
Oh and thanks for the site -- I'll look into it (: