C或C++中getline有几个?

来源:百度知道 编辑:UC知道 时间:2024/05/10 14:15:24
std::getline和cin.getline一样吗?

功能一样, 形式不一样呀.

前一个是普通函数,后一个是成员函数

应该一样吧

std::getline
template<class E, class T, class A>
basic_istream<E, T>& getline(
basic_istream <E, T>& is,
basic_string<E, T, A>& str);
template<class E, class T, class A>
basic_istream<E, T>& getline(
basic_istream <E, T>& is,
basic_string<E, T, A>& str,
E delim);
The first template function returns getline(is, str, is.widen('\n')).

The second template function replaces the sequence controlled by str with a sequence of elements extracted from the stream is. 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 is.max_size() elements, in which case the f