basic_istream::operator>> 被稱為提取運算符。此運算符用於應用於輸入字符串。頭文件:
<iostream>
用法:
basic_istream& operator>>( int& a ); basic_istream& operator>>( unsigned int& a );
Parameters:
- a:這表示存儲提取字符的值。
返回值:istream::operator>> 返回 basic_istream 對象。下麵是說明 std::basic_istream::operator>>:Program 1 的程序:
CPP14
// C++ code for basic_istream::operator>>
#include <bits/stdc++.h>
using namespace std;
// Driver code
int main()
{
// Declare the string "12 12.2 GeeksforGeeks"
string gfg = "12 12.2 GeeksforGeeks";
istringstream stream(gfg);
int a;
float b;
bool c;
stream >> a >> b >> boolalpha >> c;
cout << "a = " << a << '\n'
<< "b = " << b << '\n'
<< "c = " << boolalpha << c << endl;
return 0;
}
輸出:
a = 12 b = 12.2 c = false
程序2:
CPP14
// C++ code for basic_istream::operator>>
#include <bits/stdc++.h>
using namespace std;
// Driver code
int main()
{
// Declare the string "144 0.26 GFG"
string gfg = "144 0.26 GFG";
istringstream stream(gfg);
int a;
float b;
bool c;
stream >> a >> b >> boolalpha >> c;
cout << "a = " << a << '\n'
<< "b = " << b << '\n'
<< "c = " << boolalpha << c << endl;
return 0;
}
輸出:
a = 144 b = 0.26 c = false
參考:http://www.cplusplus.com/reference/istream/basic_istream/operator%3E%3E/
注:本文由純淨天空篩選整理自bansal_rtk_大神的英文原創作品 basic_istream::operator>> in C++。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。