65,211
社区成员
发帖
与我相关
我的任务
分享lz直接贴代码不好么?
还非要下载~~~
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 function calls setstate(ios_base::failbit).
If the function extracts no elements, it calls setstate(failbit). In any case, it returns *this.
See the related sample program.
//////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// Getline.cpp : Illustrates how to use the getline function to read a
// line of text from the keyboard.
//
// Functions:
//
// getline Returns a string from the input stream.
//////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <string>
#include <iostream>
using namespace std ;
void main()
{
string s1;
cout << "Enter a sentence (use <space> as the delimiter):";
getline(cin,s1, ' ');
cout << "You entered: " << s1;
}