I just started learning C++. I was just playing around with it and came across a problem which involved taking input of a string word by word, each word separated by a whitespace. What I mean is, suppose I have
name place animal
as the input. I want to read the first word, do some operations on it. Then read the second word, do some operations on that, and then read the next word, so on.
I tried storing the entire string at first with getline like this
#include<iostream>
using namespace std;
int main()
{
string t;
getline(cin,t);
cout << t; //just to confirm the input is read correctly
}
But then how do I perform operation on each word and move on to the next word?
Also, while googling around about C++ I saw at many places, instead of using "using namespace std" people prefer to write "std::" with everything. Why's that? I think they do the same thing. Then why take the trouble of writing it again and again?
See Question&Answers more detail:os