国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C++ > 正文

C++ 中cerr和cout的區(qū)別實例詳解

2020-01-26 13:54:54
字體:
來源:轉載
供稿:網友

C++ 中cerr和cout的區(qū)別實例詳解

前言:

 cerrThe object controls unbuffered insertions to the standard error output as a byte stream. Once the object is nstructed, the expression cerr.flags & unitbuf is nonzero.

  Example

 // iostream_cerr.cpp// compile with: /EHsc// By default, cerr and clog are the same as cout#include <iostream>#include <fstream> using namespace std; void TestWide( ) { int i = 0; wcout << L"Enter a number: "; wcin >> i; wcerr << L"test for wcerr" << endl; wclog << L"test for wclog" << endl; } int main( ) { int i = 0; cout << "Enter a number: "; cin >> i; cerr << "test for cerr" << endl; clog << "test for clog" << endl; TestWide( );}  
 Input  Sample Output Enter a number: 3test for cerrtest for clogEnter a number: 1test for wcerrtest for wclogcout The object controls insertions to the standard output as a byte stream. cerr extern ostream cerr; The object controls unbuffered insertions to the standard error output as a byte stream. Once the object is constructed, the expression cerr.flags() & unitbuf is nonzero.  cout extern ostream cout; The object controls insertions to the standard output as a byte stream. 

cerr: 錯誤輸出流,無緩沖,不可以重定向。輸出的數(shù)據(jù)不經過緩沖區(qū),直接放到指定的目標中,既然不經過緩沖區(qū)那么其它程序就無法把要輸出的內容送到其他目標中,所以說它不能被重定向。 

cout:標準輸出流,有緩沖,可重定向。把要輸出的數(shù)據(jù)先放到緩沖區(qū)中,然后再從緩沖區(qū)到你指定的設備中。當向cout流插入一個endl,不論緩沖區(qū)是否漫了,都立即輸出流中所有數(shù)據(jù),然后插入一個換行符. 

注:Linux下可以用標準錯誤輸出間接重定向cerr的輸出

如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 公安县| 柳州市| 康乐县| 黄浦区| 潼南县| 西丰县| 通州区| 吉安县| 建始县| 宿松县| 巴林右旗| 永新县| 临漳县| 石景山区| 伊吾县| 禄劝| 惠州市| 湛江市| 黎川县| 拉萨市| 富蕴县| 淅川县| 于田县| 林芝县| 加查县| 蒲城县| 新绛县| 乌鲁木齐县| 辽阳县| 平安县| 叶城县| 东安县| 五台县| 什邡市| 卓资县| 漳浦县| 大田县| 邵阳县| 巩留县| 富顺县| 泰和县|