在不同的编译下结果会有点区别:
VC++6.0:
INPUT:
Hello enter
World enter
Why? enter
OUTPUT:
Hello World //Why?被丢弃了
VC++2005:
input:
Hello enter
World enter
OUTPUT:
Hello World 不知道这是不是VC++6.0的一个BUG。
下面为MSDN的资料:
getline
Parameters
_Istr
The input stream from which a string is to be extracted.
_Str
The string into which are read the characters from the input stream.
_Delim
The line delimiter.
Return Value
The first function returns getline( _Istr, _Str, _Istr.widen( '\n' ) ).
The second function replaces the sequence controlled by _Str with a sequence of elements extracted from the stream _Istr.
Remarks
In order of testing, extraction stops:
At end of file.
After the function extracts an element that compares equal to delim, in which case the element is neither put back nor appended to the controlled sequence.
After the function extracts str.max_size elements, in which case the function calls setstate(ios_base::failbit).
If the function extracts no elements, it calls setstate(failbit). In any case, it returns _Istr.