template <class CharType, class Traits, class Allocator > basic_istream<CharType, Traits>& getline (basic_istream<CharType, Traits>& _Istr,basic_string <CharType,Traits, Allocator> &_Str);
//上述原型包含 2 個引數:第 1 個引數是輸入流;第 2 個引數是儲存輸入內容的字串
template <class CharType, class Traits, class Allocator> basic_istream<CharType, Traits>& getline (basic_istream <CharType, Traits>&_ Istr, basic_string <CharType, Traits, Allocator>& _Str,CharType_Delim);
//上述原型包含 3 個引數:第 1 個引數是輸入流,第 2 個引數儲存輸入的字串,第 3 個引數指定分界符。
#include <iostream> #include <string> using namespace std; void main () { string s1, s2; getline(cin, s1); getline(cin, s2, ' '); cout << "You inputed chars are: " << s1 << endl; cout << "You inputed chars are: " << s2 << endl; }程式的執行結果為:
123456
asdfgh klj
You inputed chars are: 123456
You inputed chars are: asdfgh