//getline原型,来自istream文件
_Myt& __CLR_OR_THIS_CALL getline(_Elem _Str,
streamsize _Count, _Elem _Delim)
{ // get up to _Count characters into NTCS, discard _Delim
_DEBUG_POINTER(_Str);
ios_base::iostate _State = ios_base::goodbit;
_Chcount = 0;
const sentry _Ok(this, true);
if (_Ok && 0 < _Count)
{ // state okay, use facet to extract
int_type _Metadelim = _Traits::to_int_type(_Delim);
_TRY_IO_BEGIN
int_type _Meta = _Myios::rdbuf()->sgetc();
for (; ; _Meta = _Myios::rdbuf()->snextc())
if (_Traits::eq_int_type(_Traits::eof(), _Meta))
{ // end of file, quit
_State |= ios_base::eofbit;
break;
}
else if (_Meta == _Metadelim)
{ // got a delimiter, discard it and quit
++_Chcount;
_Myios::rdbuf()->sbumpc();
break;
}
else if (--_Count <= 0)
{ // buffer full, quit
_State |= ios_base::failbit;
break;
}
else
{ // got a character, add it to string
++_Chcount;
_Str++ = _Traits::to_char_type(_Meta);
}
_CATCH_IO_END
}
_Str = _Elem(); // add terminating null character
_Myios::setstate(_Chcount == 0 _State | ios_base::failbit : _State);
return (this);
}
以上就是关于C++如何自己写getline函数全部的内容,包括:C++如何自己写getline函数、、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)