basic_istream::unget()用於取出字符,並將位置減少一個字符,並使提取的字符可再次使用。頭文件:
<iostream>
用法:
basic_istream& unget();
參數:basic_istream::unget()方法不接受任何參數。返回值:函數basic_istream::unget()返回basic_istream對象。下麵是說明std::basic_istream::unget():Program 1的程序:
CPP14
// C++ code for basic_istream::unget()
#include <bits/stdc++.h>
using namespace std;
// Driver code
int main()
{
// Declare string stream
istringstream gfg("GeeksforGeeks");
char a = gfg.get();
if (gfg.unget()) {
char b = gfg.get();
cout << "We got:" << a << endl;
cout << "After ungetting the "
<< "character once again"
<< " we got:"
<< b << endl;
}
return 0;
}
輸出:
We got:G After ungetting the character once again we got:G
程序2:
CPP14
// C++ code for basic_istream::unget()
#include <bits/stdc++.h>
using namespace std;
// Driver code
int main()
{
// Declare string stream
istringstream gfg("Laptop");
char a = gfg.get();
if (gfg.unget()) {
char b = gfg.get();
cout << "We got:" << a << endl;
cout << "After ungetting the "
<< "character once again"
<< " we got:"
<< b << endl;
}
return 0;
}
輸出:
We got:L After ungetting the character once again we got:L
參考:http://www.cplusplus.com/reference/istream/basic_istream/unget/
相關用法
- C++ cin get()用法及代碼示例
- C++ std::add_lvalue_reference用法及代碼示例
- 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++ 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::bit_xor用法及代碼示例
- C++ mbrtoc16()用法及代碼示例
- C++ mbrtoc32()用法及代碼示例
- C++ ios bad()用法及代碼示例
- C++ std::is_heap()用法及代碼示例
注:本文由純淨天空篩選整理自bansal_rtk_大神的英文原創作品 basic_istream::unget() in C++ with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。