getline()与cin.getline()
高手戏玩c++ [转] - FongLuo - C++博客
getline(ifs, input); 不仅简单,而且安全,因为全局函数 getline 会帮你处理缓冲区用完之类的麻烦,如果你不希望空间...getline(cin, s, ';'); while ( s != "quit" ) { cout << s << endl; getline(cin, s, ';');...
https://www.360docs.net/doc/9c3374768.html,/FongLuo/archive/2008/05/1 ... 70K 2008-5-27 - 百度快照
basic_istream::ignore
Causes a number of elements to be skipped from the current read position.
Copy Codebasic_istream& ignore(
streamsize _Count = 1,
int_type _Delim = traits_type::eof( )
);
所以cin.ignore()就是跳过一个输入缓存中的元素;
而getline 是一个全局函数,
getline
Extract strings from the input stream line-by-line.
template
basic_istream
basic_istream
basic_string
);
template
basic_istream
basic_istream
basic_string
CharType _Delim
);
Parameter
_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.
这个程序的意思就是从标准输入设备读取一行到string s中