上一页 1 ··· 22 23 24 25 26 27 28 29 30 ··· 49 下一页
摘要: //第二十一章流 15sstream字符串输入输出流类/*#include <iostream>#include <sstream>#include <string>using namespace std;int main(){ ostringstream out; //ostringstream 类从ostream类派生而来,因此ostringstream类对像有cout对像的特征 char *str = "hello world"; float num=314.57f; out.precision(2); out<<fix 阅读全文
posted @ 2012-10-01 14:03 简单--生活 阅读(168) 评论(0) 推荐(0) 编辑
摘要: //第二十一章流 11指定读取文件中的数据seekg()//假如我们不想全部读入文件中的数据,而是只读取其中的某项数据,那么fstream类的seekg()成员函数可以为我们达到目的/*#include <iostream>#include <fstream>using namespace std;int main(){ ofstream fout("people.txt"); if(!fout){ cout<<"创建文件失败"; } fout<<"1234567890asfdsfasfasfas 阅读全文
posted @ 2012-10-01 14:02 简单--生活 阅读(1688) 评论(0) 推荐(0) 编辑
摘要: //第二十一章流 12输出数据到文件指定位置处seekp()//想要在文件指定位置处输出数据,那么fstream类的seekp()成员函数可以为我们达到目的/*#include <iostream>#include <fstream>using namespace std;int main(){ ofstream fout("people.txt"); if(!fout){ cout<<"创建文件失败"<<endl; } fout<<"ABCDEFGLIJKLMIOPQ"; 阅读全文
posted @ 2012-10-01 14:02 简单--生活 阅读(318) 评论(0) 推荐(0) 编辑
摘要: //第二十一章流 13seekp()和seekg()函数的结合使用/*#include <iostream>#include <fstream>#include <iomanip>using namespace std;const int num = 10;struct people{ char name[num]; int age; float pay;};const char*file = "people13.txt";void deleteline(){ while(cin.get() !='\n') continu 阅读全文
posted @ 2012-10-01 14:02 简单--生活 阅读(792) 评论(0) 推荐(0) 编辑
摘要: //第二十一章流 14临时文件/*#include <cstdio>#include <iostream>using namespace std;int main(){ cout<<"tmpnam()函数的最多调用次数:"<<TMP_MAX<<"\n 临时文件名的字符数目:"<<L_tmpnam<<"字符"<<endl; char pszName[L_tmpnam]={'\0'}; cout<<"下面是 阅读全文
posted @ 2012-10-01 14:02 简单--生活 阅读(151) 评论(0) 推荐(0) 编辑
摘要: // 第二十一章流 8打开多个文件// 1 同时打开多个文件// 2 依次打开多个文件,也就是打开并处理完一个文件后再打开一个文件/*#include <iostream>using namespace std;int main(){ return 0;}*/// 第二十一章流 9 命令行处理文件//int main(int argc, char** argv) //是指向char的指针的指针//int main(int argc, char* argv[]) //字符数组的指针// argc是指命令输入参数的个数/*#include <iostream>using n 阅读全文
posted @ 2012-10-01 14:01 简单--生活 阅读(214) 评论(0) 推荐(0) 编辑
摘要: //第二十一章流 10使用命令行处理文件例程/*#include <iostream>#include <fstream>using namespace std;int main(int argc, char*argv[]){ if(argc==1) { cout<<"访程序"<<argv[0]<<"未操作文件名"<<endl; exit(EXIT_FAILURE); //exit()函数就是退出程序,传入的参数是程序退出时的状态码,0表示正常退出,其他表示非正常退出 } ifstr 阅读全文
posted @ 2012-10-01 14:01 简单--生活 阅读(153) 评论(0) 推荐(0) 编辑
摘要: // 第二十一章流 5 多种打开文件的方式 文件存在,文件不存在/*ios::in 打开文件进行读操作,即读取文件中的数据ios::out 打开文件进行写操作,即输出数据到文件中ios::ate 打开文件时针指向文件末尾,但是你可以在文件中的任何地方写入数据ios::app 打开文件不会清空数据,文件指针始终在文件尾,因此只能文件尾写数据ios::trunc 默认,若打开文件已经存在,则清空文件内容ios::nocreate 若打开文件不存在则不建立,返回打开失败信息ios::noreplace 打开文件时不能覆盖,若文件存在则返回打开失败信息ios::binary 打开文件为二进制文件,否则 阅读全文
posted @ 2012-10-01 14:00 简单--生活 阅读(421) 评论(0) 推荐(0) 编辑
摘要: //第二十一章流 6检查文件是否打开// // 使用布尔函数eof() bad() fail()他good()够检查// eof()/bad()/fail()返回假时或者 good()返回真时文件打开成功/*#include <iostream>#include <fstream>using namespace std;int main(){ ofstream fout("a.txt"); fout<<"输出到文件"; fout.close(); ifstream fin("a.txt"); if( 阅读全文
posted @ 2012-10-01 14:00 简单--生活 阅读(231) 评论(0) 推荐(0) 编辑
摘要: // 第二十一章流 7二进制文件和文本文件//1 以文本形式输出到文件/*#include <iostream>#include <fstream>using namespace std;//定义一个结构体peopleconst int num=20;struct people{ char name[num]; double weight; int tall; int age; char sex;};int main(){ people pe={"李能",78.5,181,25,'f'}; ofstream fout("pe 阅读全文
posted @ 2012-10-01 14:00 简单--生活 阅读(224) 评论(0) 推荐(0) 编辑
上一页 1 ··· 22 23 24 25 26 27 28 29 30 ··· 49 下一页
简单--生活(CSDN)