string::getline
說明如何使用 string::getline Visual C++ 標準樣板程式庫 (STL) 類別。
template<class _E, class _TYPE, class _A> inline
basic_istream<_E, _TYPE>& getline(
basic_istream<_E, _TYPE>& Istream,
basic_string<_E, _TYPE, _A>& Xstring,
const _E _D=_TYPE::newline( )
);
備註
![]() |
---|
在原型中的類別/參數名稱不相符的標頭檔中的版本。某些已修改以提高可讀性。 |
Getline 函式會建立字串,包含所有輸入資料流中的字元,直到發生下列情況其中一項:-檔案結尾。 位遇到的分隔符號。 - is. max_str 已解壓縮的項目。
範例
// string_getline_sample.cpp
// compile with: /EHsc
// 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 ;
int main()
{
string s1;
cout << "Enter a sentence (use <space> as the delimiter): ";
getline(cin,s1, ' ');
cout << "You entered: " << s1 << endl;;
}
請測試這個部分
FakePre-1b3ac88fb00046e1bd395346ccf61f8e-b7170c8e28784c4eb09249e0a89b1fd1
需求
標頭: <string>