?? 11-7.txt
字號:
/* 范例:11-7 */
#include <fstream.h>
void main()
{
ofstream out_file("out.txt"); // # 1 if(變更out.txt屬性只讀,隱藏)
out_file << "My name is Peipei.\n";
out_file.put('B').put('o').put('y'); // # 2如同cout.put(ch)...
cout << "out_file.is_open()=" << out_file.is_open() << endl;
out_file.close(); // # 3
ifstream in_file("out.txt"); // # 4 if(變更為不存在文件,out1.txt)
cout << "in_file.is_open()=" << in_file.is_open() << endl; // # 5
cout << "in_file.fail()=" << in_file.fail() << endl; // # 6
cout << in_file.rdbuf(); // # 7
in_file.close(); // # 8
getchar();
}
程序執行結果:(依 #1、#4 設定而不同,兩者皆成功時,結果如下)
out_file.is_open()=1
in_file.is_open()=1
in_file.fail()=0
My name is Peipei.
Boy
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -