getline() takes in a reference to a string in arugment 2 and fills it within the function. It returns the same istream reference that is passed in as argument 1. This return value is helpful for things like:
1 2 3 4 5 6 7 8 9
ifstream in("InputFile.txt");
if(in.good())
{
std::string lineTmp;
while(getline(in,lineTmp))
{
// process line string...
}
}
When the stream has an error, or hits eof, it will break out of the while loop.
The std::getline function which you are using has the following declaration
1 2 3 4
template<class charT, class traits, class Allocator>
basic_istream<charT,traits>&
getline(basic_istream<charT,traits>& is, basic_string<charT,traits,Allocator>& str, charT delim);
So it returns a reference to input stream. At the same time it reads data in the string object that you are passing to it by reference.
As a result you can nesting the function, for example, the following way
1 2 3 4
std::string str;
int x;
std::getline( std::cin, str ) >> x;