C++中的流操縱器的unitbuf()方法用於為指定的str流設置unitbuf格式標誌。每次操作後,此標誌刷新關聯的緩衝區。
用法:
ios_base& unitbuf (ios_base& str)
參數:此方法接受str作為參數,這是格式標誌受影響的流。
返回值:此方法返回設置了unitbuf格式標誌的流str。
範例1:
// C++ code to demonstrate
// the working of unitbuf() function
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
// Initializing the character
char a, b, c;
// Stream input with leading whitespaces
istringstream iss("GFG");
// Using unitbuf()
// buffer flushed 3 times
iss >> unitbuf >> a >> b >> c;
cout << "unitbuf flag:"
<< a << endl
<< b << endl
<< c << endl;
return 0;
}
輸出:
unitbuf flag:G F G
範例2:
// C++ code to demonstrate
// the working of unitbuf() function
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
// Initializing the character
char a, b, c, d, e;
// Stream input with leading whitespaces
istringstream iss("GEEKS");
// Using unitbuf()
// buffer flushed 5 times
iss >> unitbuf >> a >> b >> c >> d >> e;
cout << "unitbuf flag:"
<< a << endl
<< b << endl
<< c << endl
<< d << endl
<< e << endl;
return 0;
}
輸出:
unitbuf flag:G E E K S
參考: http://www.cplusplus.com/reference/ios/unitbuf/
相關用法
- C++ ios manipulators right()用法及代碼示例
- C++ ios manipulators dec()用法及代碼示例
- C++ ios manipulators hex()用法及代碼示例
- C++ ios manipulators oct()用法及代碼示例
- C++ ios manipulators noshowbase()用法及代碼示例
- C++ ios manipulators noshowpos()用法及代碼示例
- C++ ios manipulators showbase()用法及代碼示例
- C++ ios manipulators fixed()用法及代碼示例
- C++ ios manipulators left()用法及代碼示例
- C++ ios manipulators noskipws()用法及代碼示例
- C++ ios manipulators boolalpha()用法及代碼示例
- C++ ios manipulators uppercase()用法及代碼示例
- C++ ios manipulators nounitbuf()用法及代碼示例
- C++ ios manipulators scientific()用法及代碼示例
- C++ ios manipulators noshowpoint()用法及代碼示例
注:本文由純淨天空篩選整理自guptayashgupta53大神的英文原創作品 ios manipulators unitbuf() function in C++。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。