国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 南康市| 香格里拉县| 嘉义县| 宁阳县| 集贤县| 龙山县| 海门市| 简阳市| 中卫市| 额济纳旗| 韶山市| 平利县| 宝应县| 浙江省| 富宁县| 容城县| 高邮市| 宾阳县| 秦安县| 化德县| 海兴县| 建平县| 西和县| 招远市| 新竹县| 洛浦县| 桂林市| 台北县| 尚义县| 营山县| 根河市| 四川省| 禄丰县| 诏安县| 清涧县| 奇台县| 银川市| 湖南省| 隆林| 定远县| 于田县|