- /*
- #include <fstream>
- #include<iostream>
- using namespace std;
- int main()
- {
- fstream File("test.txt",ios::in | ios::out);
- File << "Hi!choiminho!\ndfhsajfk dskfaj\n fafsaaajf"; //将"Hi!"写入文件
- ///static char str[10]; //当使用static时,数组会自动被初始化
- //即是被清空为零
- */
- /* File.seekg(ios::beg); // 回到文件首部
- // 此函数将在后面解释
- ifstream OpenFile("test.txt");
- char str[30]; //每个单词的长度不能超过30个字符
- while(!OpenFile.eof())
- {
- OpenFile >> str;
- cout << str << endl;
- }
- */
- /*
- ifstream OpenFile("test.txt");
- File.seekg(ios::beg); // 回到文件首部
- // 此函数将在后面解释
- char line[100]; //每个整行将会陆续被存储在这里
- while(!OpenFile.eof())
- {
- OpenFile.getline(line,100); // 100是数组的大小
- cout << line << endl;
- }
- File.close();
- return 0;
- }
- */
- /*
- 单词:
- Hi!choiminho!
- dfhsajfk
- dskfaj
- fafsaaajf
- Process returned 0 (0x0) execution time : 0.583 s
- Press any key to continue.
- */
- /*
- 整行读取:
- Hi!choiminho!
- dfhsajfk dskfaj
- fafsaaajf
- Process returned 0 (0x0) execution time : 0.620 s
- Press any key to continue.
- */
- /*
- 小科普:
- exit(0)与exit(1)、return区别
- exit(0):正常运行程序并退出程序;
- exit(1):非正常运行导致退出程序;
- return():返回函数,若在主函数中,则会退出函数并返回一值。
- 详细说:
- 1. return返回函数值,是关键字; exit 是一个函数。
- 2. return是语言级别的,它表示了调用堆栈的返回;而exit是系统调用级别的,它表示了一个进程的结束。
- 3. return是函数的退出(返回);exit是进程的退出。
- 4. return是C语言提供的,exit是操作系统提供的(或者函数库中给出的)。
- 5. return用于结束一个函数的执行,将函数的执行信息传出个其他调用函数使用;exit函数是退出应用程序,
- 删除进程使用的内存空间,并将应用程序的一个状态返回给OS,这个状态标识了应用程序的一些运行信息,这
- 信息和机器和操作系统有关,一般是 0 为正常退出, 非0 为非正常退出。
- 6. 非主函数中调用return和exit效果很明显,但是在main函数中调用return和exit的现象就很模糊,多数情
- 况下现象都是一致的。
- */
- /*
- #include<fstream>
- #include<iostream>
- #include<stdlib.h>
- using namespace std;
- int main()
- {
- ofstream SaveFile("minho.txt");
- SaveFile << "minho oppa maoxida!";
- if (!SaveFile)
- {
- cout << "Error opening the file! Aborting…/n";
- exit(1);
- }
- return 0;
- }
- */
- /*
- #include<iostream>
- #include<fstream>
- using namespace std;
- int main()
- {
- fstream file1;
- file1.open("shinee.txt");
- file1 << hex <<123;
- return 0;
- }
- */
- /*
- #include<iostream>
- #include<fstream>
- using namespace std;
- int main()
- {
- fstream file1;
- file1.open("shinee.txt");
- int i;
- file1 >> i;
- file1 << hex <<123;
- return 0;
- }
- */
- /*
- shinee的变化:
- 15 16
- 7b5 16
- 15 16
- 15 7b
- */
来源: http://lib.csdn.net/snippet/ios/42849