string::operator>>
說明如何使用 string::operator >> Visual C++ 標準樣板程式庫 (STL) 函式。
template<class E, class TYPE, class A> inline
basic_istream<E, TYPE>&
operator>>(basic_istream<E, TYPE>& InStream,
basic_string<E, TYPE, A>& String);
備註
![]() |
---|
在原型中的類別/參數名稱不相符的標頭檔中的版本。某些已修改以提高可讀性。 |
運算子 >> 用來填入字串輸入的資料流的內容。
![]() |
---|
此運算子會將資料從輸入來源複製到變數。如果輸入未經過驗證,這可能會導致緩衝區溢位。如需詳細資訊,請參閱避免緩衝區滿溢,。 |
範例
// string_operator_extract_sample.cpp
// compile with: /EHsc
//
// Illustrates how to use the operator>> to extract
// a string from an input stream, populating a string
// variable with the contents.
//
// Functions:
//
// operator>> Extracts a string from an input stream.
//////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include <string>
#include <iostream>
using namespace std ;
int main()
{
string s1;
cout << "Enter a word: ";
cin >> s1;
cout << "You entered: " << s1 << endl;
}
測試
測試 輸入一字: 測試 您輸入: 測試
需求
標頭: <string>