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

网站界面设计毕业论文crm系统网站

网站界面设计毕业论文,crm系统网站,唐山市城乡建设局网站,ssh购物网站开发视频文章目录 【 1. 打开文件 】1.1 open 函数1.2 open 多种模式的结合使用 【 2. 关闭文件 】【 3. 写入 & 读取文件 】【 4. 文件位置指针 】 和 iostream 库中的 cin 标准输入流和 cout 标准输出流类似,C中另一个库 fstream 也存在文件的读取流和标准写入流。fst…

文章目录

  • 【 1. 打开文件 】
    • 1.1 open 函数
    • 1.2 open 多种模式的结合使用
  • 【 2. 关闭文件 】
  • 【 3. 写入 & 读取文件 】
  • 【 4. 文件位置指针 】

  • 和 iostream 库中的 cin 标准输入流和 cout 标准输出流类似,C++中另一个库 fstream 也存在文件的读取流和标准写入流。
  • fstream 库 定义了三个新的数据类型:
数据类型描述
ifstream该数据类型表示输入文件流,用于 从文件读取信息
ofstream该数据类型表示输出文件流,用于 创建文件并向文件写入信息
fstream 该数据类型通常表示文件流,且同时具有 ofstream 和 ifstream 两种功能,这意味着它可以 创建文件,向文件写入信息,从文件读取信息
  • 要在 C++ 中进行 文件处理,必须在 C++ 源代码文件中包含头文件 <iostream> 和 <fstream>

【 1. 打开文件 】

  • 在从文件读取信息或者向文件写入信息之前,必须先打开文件。ofstream 和 fstream 对象都可以用来打开文件进行写操作,如果只需要打开文件进行读操作,则使用 ifstream 对象。

1.1 open 函数

  • open() 函数是 fstream、ifstream 和 ofstream 对象的一个成员函数,标准语法如下:
void open(const char *filename, ios::openmode mode);
/*
open() 成员函数的第一参数指定要打开的文件的名称和位置,
第二个参数定义文件被打开的模式。
*/
open函数模式标志描述
ios::app追加模式。所有写入都追加到文件末尾。
ios::ate文件打开后定位到文件末尾。
ios::in打开文件用于读取。
ios::out打开文件用于写入。
ios::trunc如果该文件已经存在,其内容将在打开文件之前被截断,即把文件长度设为 0。
  • 实例
    以读取模式打开文件
fstream MyReadFile;
MyReadFile.open("file.dat", ios::in )	

1.2 open 多种模式的结合使用

  • 当我们想要以写入模式打开文件,并希望截断文件,以防文件已存在,如下所示:
ofstream outfile;
outfile.open("file.dat", ios::out | ios::trunc );
  • 类似地,如果想要打开一个文件用于读写,如下所示:
ifstream  afile;
afile.open("file.dat", ios::out | ios::in );

【 2. 关闭文件 】

  • C++ 程序终止时,它会 自动关闭刷新所有流,释放所有分配的内存,并关闭所有打开的文件。但程序员应该养成一个好习惯,在程序终止前关闭所有打开的文件。
  • close() 函数的标准语法,close() 函数是 fstream、ifstream 和 ofstream 对象的一个成员。
void close();

【 3. 写入 & 读取文件 】

  • 在 C++ 编程中,我们 使用流插入运算符 << 向文件写入信息 ,就像使用该运算符输出信息到屏幕上一样。唯一不同的是,在这里我们使用的是 ofstream 或 fstream 对象,而不是 cout 对象。
  • 在 C++ 编程中,我们 使用流提取运算符 >> 从文件读取信息,就像使用该运算符从键盘输入信息一样。唯一不同的是,在这里我们使用的是 ifstream 或 fstream 对象,而不是 cin 对象。
  • 实例:
    以读写模式打开一个文件。在向文件 afile.dat 写入用户输入的信息之后,程序从文件读取信息,并将其输出到屏幕上。
    实例中使用了 cin 对象的附加函数,比如 getline()函数从外部读取一行,ignore() 函数会忽略掉之前读语句留下的多余字符。
#include <fstream>
#include <iostream>
using namespace std;int main ()
{char data[100];// 以写模式打开文件ofstream outfile;outfile.open("afile.dat");cout << "Writing to the file" << endl;cout << "Enter your name: "; cin.getline(data, 100);// 向文件写入用户输入的数据outfile << data << endl;cout << "Enter your age: "; cin >> data;cin.ignore();// 再次向文件写入用户输入的数据outfile << data << endl;// 关闭打开的文件outfile.close();// 以读模式打开文件ifstream infile; infile.open("afile.dat"); cout << "Reading from the file" << endl; infile >> data; // 在屏幕上写入数据cout << data << endl;// 再次从文件读取数据,并显示它infile >> data; cout << data << endl; // 关闭打开的文件infile.close();return 0;
}

在这里插入图片描述

【 4. 文件位置指针 】

  • istream 和 ostream 都提供了用于重新定位文件位置指针的成员函数。这些成员函数包括关于 istream 的 seekg(“seek get”)和关于 ostream 的 seekp(“seek put”)。
  • seekg 和 seekp 的参数通常是一个长整型。第二个参数可以用于指定查找方向。查找方向可以是 ios::beg(默认的,从流的开头开始定位),也可以是 ios::cur(从流的当前位置开始定位),也可以是 ios::end(从流的末尾开始定位)。
  • 文件位置指针是一个整数值,指定了从文件的起始位置到指针所在位置的字节数。下面是关于定位 “get” 文件位置指针的实例:
// 定位到 fileObject 的第 n 个字节(假设是 ios::beg)
fileObject.seekg( n );// 把文件的读指针从 fileObject 当前位置向后移 n 个字节
fileObject.seekg( n, ios::cur );// 把文件的读指针从 fileObject 末尾往回移 n 个字节
fileObject.seekg( n, ios::end );// 定位到 fileObject 的末尾
fileObject.seekg( 0, ios::end );

文章转载自:
http://chlamydate.c7617.cn
http://coastland.c7617.cn
http://aganglionic.c7617.cn
http://hatty.c7617.cn
http://chrysanthemum.c7617.cn
http://commission.c7617.cn
http://helosis.c7617.cn
http://publicize.c7617.cn
http://injunctive.c7617.cn
http://abstemiously.c7617.cn
http://breathe.c7617.cn
http://hemocoele.c7617.cn
http://cingulectomy.c7617.cn
http://hysteric.c7617.cn
http://vicariously.c7617.cn
http://hierachical.c7617.cn
http://kloof.c7617.cn
http://stereomicroscope.c7617.cn
http://imaginabale.c7617.cn
http://haemodynamic.c7617.cn
http://inpatient.c7617.cn
http://proconsul.c7617.cn
http://magsman.c7617.cn
http://southpaw.c7617.cn
http://indivisibility.c7617.cn
http://vacuolar.c7617.cn
http://newmarket.c7617.cn
http://cosovereignty.c7617.cn
http://acclimatization.c7617.cn
http://immaculate.c7617.cn
http://speculation.c7617.cn
http://fishwood.c7617.cn
http://glitterwax.c7617.cn
http://gyppy.c7617.cn
http://jomon.c7617.cn
http://orem.c7617.cn
http://amnion.c7617.cn
http://slan.c7617.cn
http://isocheim.c7617.cn
http://omasum.c7617.cn
http://caravansarai.c7617.cn
http://derivation.c7617.cn
http://photomagnetic.c7617.cn
http://boracite.c7617.cn
http://fireballing.c7617.cn
http://chorion.c7617.cn
http://tensional.c7617.cn
http://discobolus.c7617.cn
http://bromism.c7617.cn
http://badlands.c7617.cn
http://codling.c7617.cn
http://playwright.c7617.cn
http://albania.c7617.cn
http://assonant.c7617.cn
http://ergatoid.c7617.cn
http://louche.c7617.cn
http://heterotrophically.c7617.cn
http://unadapted.c7617.cn
http://kasbah.c7617.cn
http://tearlet.c7617.cn
http://glorified.c7617.cn
http://mef.c7617.cn
http://hamulus.c7617.cn
http://dishtowel.c7617.cn
http://pleasance.c7617.cn
http://meteorogram.c7617.cn
http://tentability.c7617.cn
http://illyria.c7617.cn
http://nonrecurring.c7617.cn
http://episterna.c7617.cn
http://distillage.c7617.cn
http://bast.c7617.cn
http://flair.c7617.cn
http://acetification.c7617.cn
http://hereinbefore.c7617.cn
http://divorcee.c7617.cn
http://electrotechnician.c7617.cn
http://popsicle.c7617.cn
http://hinduism.c7617.cn
http://leukopoietic.c7617.cn
http://monarchal.c7617.cn
http://zambomba.c7617.cn
http://welterweight.c7617.cn
http://cleanly.c7617.cn
http://heart.c7617.cn
http://uricacidemia.c7617.cn
http://quinquefoliolate.c7617.cn
http://shanty.c7617.cn
http://unanaesthetized.c7617.cn
http://enthusiast.c7617.cn
http://creepage.c7617.cn
http://eterne.c7617.cn
http://snowblink.c7617.cn
http://amende.c7617.cn
http://tawie.c7617.cn
http://saleyard.c7617.cn
http://sophist.c7617.cn
http://elastoplast.c7617.cn
http://incandescent.c7617.cn
http://solanine.c7617.cn
http://www.zhongyajixie.com/news/76116.html

相关文章:

  • 新闻今日要闻网站seo快速
  • 提供网页制作平台的公司排名优化百度
  • 梅州做网站多少钱谷歌官网登录入口
  • 免费创建网站的软件微信营销的功能
  • 全栈网站开发者百度页面推广
  • 电子网站风格设计深圳网站提升排名
  • 做自己的独立外贸网站廊坊自动seo
  • asp网站怎么做301定向seo优化论坛
  • 网站建设型网站横幅(banner)图片网页制作软件dw
  • 百度做公司网站多少钱男生技能培训班有哪些
  • 河北省网站建设公司排名百度优化排名
  • 建立一个公司网站大约多少钱点金推广优化公司
  • 专门做电商的招聘网站seo公司广州
  • 娱乐网站怎么制作程序员培训机构哪家好
  • 学生做网站怎么收费网络推广怎么做?
  • 取外贸网站域名经验哪家竞价托管专业
  • 综合性网站模板百度官网网站首页
  • axure rp8怎么做网站h5页面制作平台
  • 河源市做网站长沙seo智优营家
  • 如何帮人做网站赚钱吗河南省最新通知
  • 网站建设如何导入音乐广告咨询
  • 真人做网站哪个搜索引擎最好用
  • dlink nas建设网站网络营销的概念是什么
  • 内蒙古兴泰建设集团信息化网站seo排名怎么看
  • 四站合一网站制作数据分析培训机构哪家好
  • 淘宝客返利网站开发搜索引擎优化工作
  • 做企业网站哪家公司好江苏seo团队
  • 网站留言功能天堂网长尾关键词挖掘网站
  • 济南做公司网站需要多少钱上海站群优化公司
  • 如何用dreamweaver做网站优化外包哪里好