IO類

IO類型

rea

ifstream和istringstream 繼承自istream;ofstream和ostringstream繼承自ostream。

IO對象無法拷貝和賦值

估計這裏是禁用了拷貝和賦值函數,不能拷貝的連帶作用是不能作爲形參和返回值類型。

#include <iostream>
#include <vector>
#include <string>
#include <fstream>
using namespace std;

void f(ofstream )  //這個居然不報錯,奇怪
{}

int main() {

    ofstream out1,out2;
    out1 = out2;   //xxx,operator=(const basic_ofstream&) = delete;
    f(out2);  //xxx,也是delete

    return 0;
}

IO緩衝區刷新

下列語句可能立馬輸出,也可能不輸出,這是操作系統把要寫的內容先放到一個緩衝區,緩衝區滿再一起操作。

os<<"Please input a value:";

這時就要顯式刷新緩衝區。三種:

cout<<""<<endl;    //多打個回車
cout<<""<<ends;   //多打個空格
cout<<""<<flush; //直接刷新

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章