当前位置: 首页 > news >正文

东莞企业网站制作怎么做益阳注册公司

东莞企业网站制作怎么做,益阳注册公司,淮安 网站建设:,js做网站好吗前言 文件和平常用到的cin、cout流其实是一回事#xff0c;可以将文件看作一个有限字符构成的顺序字符流#xff0c;基于此#xff0c;也可以像cin、cout读键盘数据那样对文件进行读写。 读写指针 输入流的read指针 输出流的write指针 注#xff1a;这里的指针并不是普…前言 文件和平常用到的cin、cout流其实是一回事可以将文件看作一个有限字符构成的顺序字符流基于此也可以像cin、cout读键盘数据那样对文件进行读写。 读写指针 输入流的read指针 输出流的write指针 注这里的指针并不是普通的内存指针*ptr而是一种叫std::streampos类型的指针是用于在文件流中定位文件位置的数据类型可以类比成一个int型的数据。 文本文件读写demo #include iostream #include fstream #include algorithm #include cstring #include string.h #include vector using namespace std;int main(){vectorint v;ifstream srcFile(testin.txt, ios :: in);ofstream destFile(testout.txt, ios :: out);int t;while(srcFile t)v.push_back(t);sort(v.begin(), v.end());for(auto i : v)destFile i ;//不执行close的话数据还在内存的缓冲区里没被磁盘读走srcFile.close();destFile.close();return 0; } //testin.txt: 9 84 23 15 56 2 34 123 5 1 //testout.txt: 1 2 5 9 15 23 34 56 84 123 二进制文件读写demo1 #include iostream #include fstream #include algorithm #include cstring #include string.h #include vector using namespace std;//写入一个整型数据后接着读出 int main(){ofstream fout(some.bat, ios::out | ios::binary); //从文件头开始以二进制的形式写入int x 120;//从x的内存地址开始传入4字节数据//(const char*)强转是为了让编译器拿到(int*)指针后能将其解释成字符型数据fout.write((const char*) x, sizeof(int));fout.close();int y;ifstream fin(some.bat, ios::in | ios::binary);//从文件头开始以二进制的形式写入//从文件开头处取出4字节数据//然后将y地址转成(char*)从而在该地址后面放入4字节数据fin.read((char*) y, sizeof(int));fin.close();cout y endl;return 0; }二进制文件读写demo2 先写入三个对象的数据 #include iostream #include fstream #include algorithm #include cstring #include string.h #include vector using namespace std; struct Student{char name[20];int score; };//24-Byteint main(){Student s;ofstream OutFile(students.dat, ios::out|ios::binary);while(cin s.name s.score)OutFile.write((char*) s, sizeof(s));OutFile.close();return 0; } //input: //Tom 60 //Jack 80 //Jane 40 //^Z Enter读出并合理地显示内容 #include iostream #include fstream #include algorithm #include cstring #include string.h #include vector using namespace std; struct Student{char name[20];int score; };//24-Byteint main(){Student s;ifstream inFile(students.dat, ios::in|ios::binary);if(!inFile){ //空流cerr error endl;return 0;}while(inFile.read((char*) s, sizeof(s))){int readBytes inFile.gcount(); //本次读进来了多少字节数据cout readBytes: readBytes endl;cout s.name s.score endl;}inFile.close();return 0; } //output: //readBytes: 24 //Tom 60 //readBytes: 24 //Jack 80 //readBytes: 24 //Jane 40二进制文件读写demo3 用一个fstream流对象完成读和写的任务 #include iostream #include fstream #include algorithm #include cstring #include string.h #include vector using namespace std; struct Student{char name[20];int score; };//24-Byte //Jane——Mike int main(){Student s;fstream iofile(students.dat, ios::in|ios::out|ios::binary);if(!iofile){cerr error endl;return 0;}iofile.seekp(2 * sizeof(s), ios::beg); //从文件头开始将写指针移动两个对象大小的跨度——到第三个对象的首字节//由于Mike和Jane同字符个数所以写入Mike后e的后面已经是\0了其实可以不“1”让编译器来补终止符。iofile.write(Mike, strlen(Mike) 1); iofile.seekg(0, ios::beg); //防止读指针随机指到其他地方while(iofile.read((char*) s, sizeof(s))){int readBytes iofile.gcount();cout readByte: readBytes endl;cout s.name s.score endl;}iofile.close();return 0; } // output: // readByte: 24 // Tom 60 // readByte: 24 // Jack 80 // readByte: 24 // Mike 40总结 文本模式和二进制模式的主要区别在于文本模式会执行一些与文本数据处理相关的特殊转换和处理比如Windows下所有的\r\n会被解释成一个\n字符从而造成数据读取泄漏而二进制模式不会执行这些操作二进制模式保留原数据。这里写入、读出时总利用char*作为参数的其中之一作用是为了更好地观察、理解数据否则其他数据类型打开在用户视角是一片乱码可以用记事本打开dat文件验证。
http://www.hkea.cn/news/14366113/

相关文章:

  • 做简历那些网站比较好百度趋势搜索
  • 金融网站建设案例怎么在微信创建公众号
  • 在网站的标题上怎么做图标网站开发技术文档格式
  • 企业网站模块国医堂网站平台建设
  • .net 网站自动登录平台推广营销方案
  • 网站设计网站项目流程图免费建官方网站
  • 如何制作一个php网站源码商务网站价格
  • 商业网站开发的实训小结怎么写一键logo设计官网
  • 建设银行网站点不进去了怎么办长春网站制作平台
  • 介绍个人网站的ppt怎么做网络营销模式有几种
  • 天津网站建设优化有经验的企业做网站
  • 雅安建设局网站深圳网站建设快速排名
  • 余姚做网站设计的公司深圳华强北手机城
  • asp网站后台失效网站建设制作设计公司
  • 国外时尚设计网站营销型网站北京
  • 网站推广一般在哪个网做银川做网站
  • 网站打开前潮网络网站建设
  • 网站注册网站设计专业知识技能
  • 手机网站模板 html查询域名注册信息
  • 免费建单页网站小程序一般需要多少钱
  • 吴志祥最早做的网站是什么网站wordpress怎么改搜索
  • 海兴做网站价格建筑培训网成绩查询
  • 商城网站哪个公司做的好青浦网站制作
  • 有没有给人做简历的网站泰州网站制作
  • 网站建设设计制作 熊掌号手机app制作开发
  • 怎么去找做网站的自助建站网站seo公司
  • 消防网站建设的风格网站开发研究方法
  • 山西省网站建设哪里好申请邮箱企业邮箱
  • 网站开发包括网站的乔拓云的品牌推广方案
  • wordpress大学主题下载地址关键词优化排名技术