close

ofstream 類別可以              ios::trunc模式開啟檔案,

fstream   類別可以ios::out| ios::trunc模式開啟檔案,

且開啟效果與 ios::out相同,即檔案不存在,則開啟一個空白檔案,檔案存在則開啟舊檔,並刪除檔案內容(結論:無論檔案是否存在均開啟一個空白檔案),但

ifstream 類別無法以 ios::trunc模式開啟

ifstream file("data.txt", ios::trunc );

failbit ,eofbit ,  badbit , 與goodbit的 加權值 輸出格式.

cout<<"ios::failbit    = "<<ios::failbit    <<endl;
cout<<"ios::eofbit    = "<<ios::eofbit    <<endl;
cout<<"ios::badbit   = "<<ios::badbit   <<endl;
cout<<"ios::goodbit = "<<ios::goodbit<<endl<<endl;

測試檔案是否正常開啟的 fail() ,  eof() , bad()與 good()成員函式格式.  
 cout<<"file.fail()      = "<<file.fail()       <<endl;
 cout<<"file.eof()     = "<<file.eof()       <<endl;
 cout<<"file.bad()    = "<<file.bad()      <<endl;
 cout<<"file.good() = "<<file.good()    <<endl;

ios::nocreate     //若檔案不存在,則檔案開啟失敗

ios::noreplace   //若檔案存在   ,則檔案開啟失敗

arrow
arrow
    文章標籤
    ios::failbit ios:: badbit  test
    全站熱搜

    minsin 發表在 痞客邦 留言(0) 人氣()