自己乱写的文件输入输出例程 乱到极致 心脏不好的勿入
2016-05-21 15:36
260 查看
<pre name="code" class="cpp">/* #include<fstream> #include<iostream> #include<string> using namespace std; int main() { ofstream File1("love.txt"); File1 << "minho oppa salanghei\n woohyun oppa\nsalanghei"; File1.close(); ifstream File("love.txt"); File.seekg(ios::beg); char line[100]; while(!File.eof()) { File.getline(line,100); cout << line << endl; } File.close(); return 0; } */ /* minho oppa salanghei woohyun oppa salanghei Process returned 0 (0x0) execution time : 0.429 s Press any key to continue. */ /* #include<iostream> #include<fstream> using namespace std; int main() { ifstream file("shinee.txt"); int a[3]; for(int i=0; i<3; i++) { file >> a[i]; cout << a[i] << endl; } return 0; } */ /* #include<iostream> #include<fstream> using namespace std; int main() { ofstream file("fighting.txt"); int a[4]; int b[4]; for(int i=0; i<4; i++) { cin >> a[i]; file << a[i] << endl; } file.close(); ifstream file1("fighting.txt"); for(int i=0; i<4; i++) { file1 >> b[i]; cout << b[i] << endl; } } */ #include<iostream> #include<fstream> using namespace std; int main() { int a; ofstream file("fighting.txt"); file << 123; file.close(); ifstream file1("fighting.txt"); file1 >> a; cout << hex << a << endl; }
#include <fstream>#include<iostream>using namespace std;int main(){ fstream File("test.txt",ios::in | ios::out); File << "Hi! choiminho!"; //将“Hi!”写入文件 ,为什么不识别我家珉豪欧巴呢,因为他太帅了!开玩笑啦!因为空格呦。 ///static char str[10]; //当使用static时,数组会自动被初始化 //即是被清空为零 ifstream OpenFile("test.txt");
File.seekg(ios::beg); // 回到文件首部 // 此函数将在后面解释 File >> str; cout << str << endl; File.close(); return 0;}*/
/* #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 */
相关文章推荐
- Android中Widget (微件、小组件)
- OpenCV中的按钮问题
- PHP数组
- 子过程左值属性
- 子过程左值属性
- iOS - 修改UITextField的placeholder颜色
- Quartz2D 编程指南(二)变换、图案、阴影
- Adroid我还是个菜鸟——导入jar包
- 第4课:Spark Streaming的Exactly-One的事务处理和不重复输出彻底掌握
- svn创建搭建教程
- Django中连接Mysql报错 No module named MySQLdb
- C++迷宫问题(BFS)
- Activity跳转Flag详解
- [Machine Learning & Algorithm]CAML机器学习系列2:深入浅出ML之Entropy-Based家族
- android 动画 ——alpha、scale、translate、rotate、set的xml属性及用法
- 互联网金融爬虫怎么写-第一课 p2p网贷爬虫(XPath入门)
- JavaScript插入节点小结
- springMvc
- LeetCode|Surrounded Regions
- 利用Fiddler进行模拟限速测试