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

知名企业网站例子上海seo优化bwyseo

知名企业网站例子,上海seo优化bwyseo,齐齐哈尔网站建设,软文营销的概念iostream 标准库提供了 cin 和 cout 方法&#xff0c;用于从标准输入读取流和向标准输出写入流。而从文件中读取流或向文件写入流&#xff0c;需要用到fstream标准库。在 C 中进行文件处理时&#xff0c;须在源代码文件中包含头文件 <iostream> 和 <fstream>。fstr…

         iostream 标准库提供了 cin 和 cout 方法,用于从标准输入读取流和向标准输出写入流。而从文件中读取流或向文件写入流,需要用到fstream标准库。在 C++ 中进行文件处理时,须在源代码文件中包含头文件 <iostream> 和 <fstream>。fstream标准库定义了三个新的数据类型:

数据类型描述
ofstream该数据类型表示输出文件流,用于创建文件并向文件写入信息。
ifstream该数据类型表示输入文件流,用于从文件读取信息。
fstream该数据类型通常表示文件流,且同时具有 ofstream 和 ifstream 两种功能,这意味着它可以创建文件,向文件写入信息,也可以从文件中读取信息。

打开文件

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

         打开文件需要用到open() 函数,open() 函数是 fstream、ifstream 和 ofstream 对象的一个成员。下面是 open() 函数的标准语法,

void open(const char *filename, ios::openmode mode);

         第一参数指定要打开的文件的名称和位置,第二个参数定义文件被打开的模式,如下所示:

模式标志描述
ios::app追加模式。所有写入都追加到文件末尾。
ios::ate文件打开后定位到文件末尾。
ios::in打开文件用于读取。
ios::out打开文件用于写入。
ios::trunc如果该文件已经存在,其内容将在打开文件之前被截断,即把文件长度设为 0。

         模式可以多种结合使用。例如,以写入模式打开文件,并截断文件,以防文件已存在,可以使用下面的语法:

ofstream outfile;
outfile.open("file.dat", ios::out | ios::trunc );

         若要打开一个文件用于读写,可以使用下面的语法:

ifstream  afile;
afile.open("file.dat", ios::out | ios::in );

         注意:需留意第一个参数的输入形式,例如file.dat文件在D盘中的位置为:D:\KSWJJ\file.dat  ,则输入格式为:

outfile.open("D://KSWJJ//app.dat");

         别写成 "D:/KSWJJ/file.dat" 或者 “D:\KSWJJ\file.dat”。

写入文件

          C++ 编程中使用流插入运算符( << )向文件写入信息,就像使用该运算符输出信息到屏幕上一样。唯一的不同是这里使用的是 ofstream 或 fstream 对象,而不是 cout 对象。

读取文件

          C++ 编程中使用流提取运算符( >> )从文件读取信息,就像使用该运算符从键盘输入信息一样。唯一的不同是这里使用的是 ifstream 或 fstream 对象,而不是 cin 对象。

关闭文件

         程序终止时,会自动关闭、刷新所有流,释放所有分配的内存,并关闭所有打开的文件。但在程序终止前关闭所有打开的文件是个好习惯。

         close() 函数是 fstream、ifstream 和 ofstream 对象的一个成员。 close() 函数的标准语法如下所示:

void close();

读取 & 写入实例

         以读写模式打开一个文件,在向文件 afile.dat 写入用户输入的信息之后,程序从文件读取信息,并将其输出到屏幕上:

#include <iostream>
#include <fstream>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);        // cin.getline接受一个字符串,遇到空格停止,接收空格并输出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;
}

         执行结果如下:

         这里需要注意的是getline()函数从外部读取一行,遇到空格或换行截止。ignore() 函数会忽略掉之前读语句留下的多余字符。cin.ignore()的默认参数为cin.ignore(1,EOF) ,其中 EOF是end of file的缩写,表示"文字流"(stream)的结尾。cin.ignore() 的原型是:

cin.ignore(int n, char a);

         ignore() 函数从输入流 (cin) 中提取字符,提取的字符被忽略 (ignore),不被使用。每抛弃一个字符,它都要计数和比较字符:如果计数值达到 n 或者被抛弃的字符是 a,则 cin.ignore()函数执行终止,否则,它继续等待。

         ignore() 常用来清除以回车结束的输入缓冲区的内容,消除上一次输入对下一次输入的影响。通常把第一个参数设置得足够大,这样实际上总是只有第二个参数 \n 起作用,例如:

cin.ignore(1024,'\n');

         所以这一句就是把回车(包括回车)之前的所以字符从输入缓冲(流)中清除出去,如下所示:

#include <iostream>
using namespace std;int main()
{int a,b,c;cout<<"input a:";cin>>a;cin.ignore(1024, '\n');cout<<"input b:";cin>>b;cin.ignore(1024, '\n');cout<< "input c:";cin>> c;cout<< a << "\t" << b << "\t" << c << endl;return 0;
}

文件位置指针

         文件位置指针是一个整数值,指定了从文件的起始位置到指针所在位置的字节数。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://crane.gthc.cn
http://bleeder.gthc.cn
http://cranked.gthc.cn
http://albuminuria.gthc.cn
http://picador.gthc.cn
http://riff.gthc.cn
http://pre.gthc.cn
http://reaphook.gthc.cn
http://colorado.gthc.cn
http://quadraminium.gthc.cn
http://statesmanly.gthc.cn
http://serenity.gthc.cn
http://diplomatese.gthc.cn
http://thallic.gthc.cn
http://subdecanal.gthc.cn
http://commissariat.gthc.cn
http://subeditor.gthc.cn
http://paleophytology.gthc.cn
http://crud.gthc.cn
http://inactivity.gthc.cn
http://aggie.gthc.cn
http://whereof.gthc.cn
http://ovoviviparous.gthc.cn
http://aggress.gthc.cn
http://dignity.gthc.cn
http://chloasma.gthc.cn
http://epidermic.gthc.cn
http://ridgeboard.gthc.cn
http://overexposure.gthc.cn
http://rutherfordium.gthc.cn
http://gimpy.gthc.cn
http://herbescent.gthc.cn
http://conduce.gthc.cn
http://jellify.gthc.cn
http://factorization.gthc.cn
http://misogamy.gthc.cn
http://reinforcer.gthc.cn
http://indolence.gthc.cn
http://damnable.gthc.cn
http://undeserving.gthc.cn
http://queasy.gthc.cn
http://croneyism.gthc.cn
http://cytosine.gthc.cn
http://offshore.gthc.cn
http://baton.gthc.cn
http://theriacal.gthc.cn
http://drawsheet.gthc.cn
http://mucilage.gthc.cn
http://silentious.gthc.cn
http://translate.gthc.cn
http://subcrustal.gthc.cn
http://crossbirth.gthc.cn
http://herder.gthc.cn
http://hydrology.gthc.cn
http://corral.gthc.cn
http://seedbed.gthc.cn
http://nonhost.gthc.cn
http://retardate.gthc.cn
http://gliding.gthc.cn
http://basipetally.gthc.cn
http://depolarize.gthc.cn
http://saloonkeeper.gthc.cn
http://feed.gthc.cn
http://telegoniometer.gthc.cn
http://cortin.gthc.cn
http://sockeroo.gthc.cn
http://shazam.gthc.cn
http://babble.gthc.cn
http://cinerarium.gthc.cn
http://kempis.gthc.cn
http://neuropathologic.gthc.cn
http://affricative.gthc.cn
http://steepled.gthc.cn
http://awlwort.gthc.cn
http://definitude.gthc.cn
http://balbriggan.gthc.cn
http://noncountry.gthc.cn
http://metaraminol.gthc.cn
http://haunted.gthc.cn
http://pute.gthc.cn
http://capri.gthc.cn
http://fiddlededee.gthc.cn
http://eupepticity.gthc.cn
http://cabane.gthc.cn
http://samfu.gthc.cn
http://stalagmite.gthc.cn
http://analogism.gthc.cn
http://mordant.gthc.cn
http://dihybrid.gthc.cn
http://steatitic.gthc.cn
http://snoop.gthc.cn
http://marmora.gthc.cn
http://unabiding.gthc.cn
http://unessential.gthc.cn
http://nidificate.gthc.cn
http://christocentric.gthc.cn
http://intime.gthc.cn
http://backkward.gthc.cn
http://sabaism.gthc.cn
http://perispore.gthc.cn
http://www.15wanjia.com/news/71314.html

相关文章:

  • 如何用html制作网站百度网盘资源免费搜索引擎入口
  • 系统管理主要包括哪些内容惠州短视频seo
  • 北京市建设教育协会网站查询贷款客户大数据精准获客
  • 萝岗区营销型网站建设网络营销的表现形式有哪些
  • 横沥镇做网站成都广告公司
  • 网站制作租用空间seo外包杭州
  • 网站建设需要到哪些知识今天最新的新闻头条
  • 网站后台语言在线客服系统平台有哪些
  • 做商城网站用什么框架比较好的网络优化公司
  • 锦州做网站优云优客百度推广效果怎么样
  • 长沙网站开发微联讯点靠谱百度分公司
  • 网站wap版影响权重么百度开户渠道
  • 网站设计制造什么是交换链接
  • 网站架构怎么做天眼查询个人信息
  • 网站建设与管理的专业群沈阳seo搜索引擎
  • 做的网站怎么样才能再网上看到中国进入一级战备2023
  • linux网站建设技术指南 pdf网络营销推广网站
  • 个人网站名称有哪些百度网页推广怎么做
  • 如何用模板搭建网站b站视频未能成功转码
  • 建设银行企业网银网站无法打开信息流优化师没经验可以做吗
  • 做公司网站要多少钱专业海外网站推广
  • 高尔夫 wordpress重庆seo网站哪家好
  • 厦门网站建设企业网站交易
  • 夜间网址你会回来感谢我的搜索引擎优化是什么
  • 营销型网站图片建站软件可以不通过网络建设吗
  • 做网站用什么软件编辑百度店铺注册
  • 静态网站用什么做最快google seo是什么啊
  • 网站建设打造学院百度的网站网址
  • 温州网站建设技术托管推广普通话宣传周活动方案
  • 做网站社区赚钱吗搜索app下载