basic_istream::get()用於獲取字符。如果可用,此函數將返回一個字符,否則將返回文件末尾。
頭文件:
<iostream>
用法:
int_type get();
參數:方法basic_istream::get()不接受任何參數。
返回值:方法basic_istream::get()返回一個字符(如果可用),否則返回文件結尾。
下麵是說明basic_istream::get()的程序
程序1:
// C++ code for basic_istream::get()
#include <bits/stdc++.h>
using namespace std;
// Driver Code
int main()
{
// Declare string stream
istringstream gfg("GeeksforGeeks");
// Here we get H
char a = gfg.get();
cout << "First character is:"
<< a << endl;
char b;
// Here we got e
gfg.get(b);
cout << "After reading:" << a
<< " We got " << b << endl;
return 0;
}
輸出:
First character is:G After reading:G We got e
程序2:
// C++ code for basic_istream::get()
#include <bits/stdc++.h>
using namespace std;
// Driver Code
int main()
{
// Declare string stream
istringstream gfg("Computer");
// Here we get C
char a = gfg.get();
cout << "First character is:"
<< a << endl;
char b;
// Here we got o
gfg.get(b);
cout << "After reading:" << a
<< " We got " << b << endl;
char c;
// Here we got m
gfg.get(c);
cout << "Now we got:"
<< c << endl;
return 0;
}
輸出:
First character is:C After reading:C We got o Now we got:m
相關用法
- C++ cin get()用法及代碼示例
- C++ std::less用法及代碼示例
- C++ std::add_lvalue_reference用法及代碼示例
- C++ std::greater用法及代碼示例
- C++ std::is_nothrow_constructible用法及代碼示例
- C++ std::is_trivially_move_constructible用法及代碼示例
- C++ std::is_trivially_move_assignable用法及代碼示例
- C++ std::is_nothrow_copy_constructible用法及代碼示例
- C++ std::make_signed用法及代碼示例
- C++ std::rank用法及代碼示例
- C++ std::is_nothrow_assignable用法及代碼示例
- C++ cauchy_distribution a()用法及代碼示例
- C++ ratio_equal()用法及代碼示例
- C++ std::to_address用法及代碼示例
- C++ std::is_trivially_assignable用法及代碼示例
- C++ std::remove_const用法及代碼示例
- C++ std::is_nothrow_destructible用法及代碼示例
- C++ std::remove_volatile用法及代碼示例
- C++ std::equal_to用法及代碼示例
注:本文由純淨天空篩選整理自bansal_rtk_大神的英文原創作品 basic_istream::get() in C++ with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。