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

wordpress做的学校网站企业关键词优化专业公司

wordpress做的学校网站,企业关键词优化专业公司,05网站,墨鱼wordpress14-1、IO流 lO流打开和关闭lO流打开模式lO流对象的状态 非格式化IO二进制IO读取二进制数据获取读长度写入二进制数据 读写指针 和 随机访问设置读/写指针位置获取读/写指针位置 字符串流 lO流打开和关闭 通过构造函数打开I/O流 其中filename表示文件路径,mode表示打…

14-1、IO流

  • lO流打开和关闭
    • lO流打开模式
    • lO流对象的状态
  • 非格式化IO
  • 二进制IO
    • 读取二进制数据
    • 获取读长度
    • 写入二进制数据
  • 读写指针 和 随机访问
    • 设置读/写指针位置
    • 获取读/写指针位置
  • 字符串流

lO流打开和关闭

通过构造函数打开I/O流
其中filename表示文件路径,mode表示打开模式

  • 打开输入流
    ifstream (const char* filename ,openmode mode)
  • 打开输出流
    ofstream(const char* filename , openmode mode);
  • 打开输入输出流
    fstream (const char* filename , openmode mode);

lO流打开模式

  • ios::out
    打开文件用于写入,不存在则创建,存在则清空
    适用于ofstream(缺省)/fstream
  • ios::app
    打开文件用于追加,不存在则创建,存在不清空
    适用于ofstream/fstream
  • ios::trunc
    打开时清空原内容
    适用于ofstream/fstream
  • ios:in
    打开文件用于读取,不存在则失败,存在不清空
    适用于ifstream(缺省)/fstream
  • ios::ate
    打开时定位文件尾
    适用于ifstream/fstream
  • ios.:binary
    以二进制模式读写
    适用于ifstream/ofstream/fstream
#include <iostream>
#include <fstream>
using namespace std;
// C++标准库已经设计好的类ofstream(文件输出流)类int main( void ){ofstream ofs1("./file",ios::out);if(!ofs1){ // !(ofs1.operator bool())cout << "ofs1流对象状态错误 -- 打开文件失败" << endl;}ofs1 << 1234 << ' ' << 56.78 << ' ' << "Hello" << '\n';if(!ofs1){cout << "ofs1流对象状态错误 -- 写文件失败" << endl;}ofs1.close();ofstream ofs2("./file",ios::app);if(!ofs2){ // !(ofs2.operator bool())cout << "ofs2流对象状态错误 -- 打开文件失败" << endl;}ofs2 << "World" << endl;;if(!ofs2){cout << "ofs2流对象状态错误 -- 写文件失败" << endl;}ofs2.close();return 0;
} 
#include <iostream>
#include <fstream>
using namespace std;
// C++标准库已经设计好的类ifstream(文件输入流)类int main( void ){ifstream ifs1("./file",ios::in);if(!ifs1){ // !(ifs1.operator bool())cout << "ifs1流对象状态错误 -- 打开文件失败" << endl;}int i; double d; string s1,s2;ifs1 >> i >> d >> s1 >> s2;if(!ifs1){cout << "ifs1流对象状态错误 -- 读文件失败" << endl;}cout << i << ' ' << d << ' ' << s1 << ' ' << s2 << endl;ifs1.close();ifstream ifs2("./file",ios::ate);if(!ifs2){ // !(ifs2.operator bool())cout << "ifs2流对象状态错误 -- 打开文件失败" << endl;}ifs2.seekg(0,ios::beg);int ii; double dd; string ss1,ss2;ifs2 >> ii >> dd >> ss1 >> ss2;if(!ifs2){cout << "ifs2流对象状态错误 -- 读文件失败" << endl;}cout << ii << ' ' << dd << ' ' << ss1 << ' ' << ss2 << endl;ifs2.close();return 0;
} 

lO流对象的状态

I/O流类对象内部保存当前状态,其值为以下常量的位或

  • ios:goodbit: 0,一切正常
  • ios::badbit: 1,发生致命错误
  • ios::eofbit: 2,遇到文件尾
  • ios::failbit: 4,打开文件失败或实际读写字节数未达预期
    在这里插入图片描述

l/O流类对象支持到bool类型的隐式转换

  • 发生1,2,4等情况,返回false,否则返回true
  • 将I/O流对象直接应用到布尔上下文中,即可实现转换

处于1或4状态的流,在复位前无法工作

#include <iostream>
#include <fstream>
using namespace std;
// C++标准库已经设计好的类ifstream(文件输入流)类int main( void ){ifstream ifs2("./file",ios::ate);if(!ifs2){ // !(ifs2.operator bool())cout << "ifs2流对象状态错误 -- 打开文件失败" << endl;}int ii; double dd; string ss1,ss2;cout << "--------------------第一次读数据-----------------------" << endl;ifs2 >> ii >> dd >> ss1 >> ss2;// ifs2.operator>>(ii).operator>>(dd)>>operator>>(ss1)>>operator>>(ss2)if(!ifs2){cout << "ifs2流对象状态错误 -- 读文件失败" << endl;cout << "ifs2是0状态吗?" << ifs2.good() << ", ifs2是1状态吗?" << ifs2.bad()<< ", ifs2是2状态吗?" << ifs2.eof() << ", ifs2是4状态吗?" << ifs2.fail() << endl;cout << "ifs2的具体状态:" << ifs2.rdstate() << endl;}cout << ii << ' ' << dd << ' ' << ss1 << ' ' << ss2 << endl;ifs2.clear();ifs2.seekg(0,ios::beg);cout << "--------------------第二次读数据-----------------------" << endl;ifs2 >> ii >> dd >> ss1 >> ss2;// ifs2.operator>>(ii).operator>>(dd)>>operator>>(ss1)>>operator>>(ss2)if(!ifs2){cout << "ifs2流对象状态错误 -- 读文件失败" << endl;cout << "ifs2是0状态吗?" << ifs2.good() << ", ifs2是1状态吗?" << ifs2.bad()<< ", ifs2是2状态吗?" << ifs2.eof() << ", ifs2是4状态吗?" << ifs2.fail() << endl;cout << "ifs2的具体状态:" << ifs2.rdstate() << endl;}cout << ii << ' ' << dd << ' ' << ss1 << ' ' << ss2 << endl;ifs2.close();return 0;
} 

非格式化IO

  • 写入字符
    ostream& ostream::put (char ch);一次向输出流写入一个字符,返回流本身
  • 刷输出流
    ostream& ostream::flush (void);将输出流缓冲区中的数据刷到设备上,返回流本身
  • 读取字符
    int istream::get (void);成功返回读到的字符,失败或遇到文件尾返回EOF
    istream& istream::get (char& ch);返回输入流本身,其在布尔上下文中的值,成功为true,失败或遇到文件尾为false
  • 读取行
    istream& istream::getline (char* buffer,streamsize num, char delim = ‘\ n’);
    • 读取字符 (至定界符)到buffer中。
    • 一旦读取了num个字符还未读取定界符,第num个字符设置为 ‘\0’,返回 (输入流对象状态为4)。
    • 如果因为遇到定界符 (缺省为 ‘\n’ ) 返回 (输入流对象状态为0)定界符被读取并丢弃,追加结尾空字符 ‘\0’,读指针停在该定界符的下一个位置
    • 遇到文件尾,返回 (输入流对象状态为6)
#include <iostream>
#include <fstream>
using namespace std;// C++标准库已经设计好的类ofstream(文件输出流)、ifstream(文件输入流)类int main( void ){ofstream ofs("./noformat",ios::out);if(!ofs)cout << "ofs流对象状态错误 -- 打开文件失败" << endl;for( char c = ' '; c <= '~';c++)ofs.put(c).flush();ofs.close();ifstream ifs("./noformat",ios::in);if(!ifs)cout << "ifs流对象状态错误 -- 打开文件失败" << endl;char c;// 单參getwhile(1){ifs.get(c);if(!ifs)break;elsecout << c;}cout << endl;ifs.clear();ifs.seekg(0,ios::beg);// 无參getwhile(1){c = ifs.get();if( c == EOF )break;elsecout << c;}cout << endl;ifs.close();return 0;
} 
#include <iostream>
#include <fstream>
using namespace std;// C++标准库已经设计好的类ofstream(文件输出流)、ifstream(文件输入流)类int main( void ){ifstream ifs("./getline",ios::in);if(!ifs)cout << "ifs流对象状态错误 -- 打开文件失败" << endl;char buf[256];while(1){ifs.getline(buf,256,'\n');if(!ifs)break;else{cout << buf << endl;cout << "ifs流对象状态值:" << ifs.rdstate() << endl;}}
/*ifs.getline(buf,256,'\n'); // aa\ncout << buf << endl;cout << "ifs流对象状态值:" << ifs.rdstate() << endl;ifs.getline(buf,256,'\n'); // bbbb\ncout << buf << endl;cout << "ifs流对象状态值:" << ifs.rdstate() << endl;ifs.getline(buf,256,'\n'); // cccccc\ncout << buf << endl;cout << "ifs流对象状态值:" << ifs.rdstate() << endl;ifs.getline(buf,256,'\n'); // dddddddd\ncout << buf << endl;cout << "ifs流对象状态值:" << ifs.rdstate() << endl;ifs.getline(buf,256,'\n'); // 0123456789\ncout << buf << endl;cout << "ifs流对象状态值:" << ifs.rdstate() << endl;ifs.getline(buf,256,'\n'); // cout << buf << endl;cout << "ifs流对象状态值:" << ifs.rdstate() << endl;
*/    ifs.close();return 0;
} 

二进制IO

读取二进制数据

istream& istream::read (char* buffer,streamsize num)
  • 从输入流中读取num个字节到缓冲区buffer中
  • 返回流对象本身,其在布尔上下文中的值,成功(读满)为true,失败(没读满)为false
  • 如果没读满num个字节,函数就返回了,比如遇到文件尾,最后一次读到缓冲区,buffer中的字节数可以通过istream::gcount()函数获得
#include <iostream>
#include <fstream>
using namespace std;// C++标准库已经设计好的类ofstream(文件输出流)、ifstream(文件输入流)类int main( void ){ofstream ofs("./binary",ios::out);if(!ofs)cout << "ofs流对象状态错误 -- 打开文件失败" << endl;ifstream ifs("./getline",ios::in);if(!ifs)cout << "ifs流对象状态错误 -- 打开文件失败" << endl;char buf[3];while(1){ifs.read(buf,3);if(ifs){ofs.write(buf,3);
//          cout << buf; // 读满3个字符}else{// 没有读满3个字符int len = ifs.gcount();ofs.write(buf,len);
//          buf[len]='\0';
//          cout << buf;break;}}ifs.close();ofs.close();return 0;
} 

获取读长度

streamsize istream::gcount (void)

返回最后一次从输入流中读取的字节数

写入二进制数据

ostream& ostream::write (const char* buffer,streamsize num);
  • 将缓冲区buffer中的num个字节写入到输出流中
  • 返回流本身,其在布尔上下文中的值,成功(写满)为true,失败(没写满)为false
#include <iostream>
#include <fstream>
using namespace std;// C++标准库已经设计好的类ofstream(文件输出流)、ifstream(文件输入流)类int main( void ){ofstream ofs("./binary",ios::out);if(!ofs)cout << "ofs流对象状态错误 -- 打开文件失败" << endl;ifstream ifs("./getline",ios::ate);if(!ifs)cout << "ifs流对象状态错误 -- 打开文件失败" << endl;int size = ifs.tellg();char buf[size];ifs.seekg(0,ios::beg);ifs.read(buf,size);ofs.write(buf,size);ifs.close();ofs.close();return 0;
} 

读写指针 和 随机访问

设置读/写指针位置

istream& istream::seekg (off_type offset,ios::seekdir origin);
ostream& ostream::seekg (off_type offset,ios::seekdir origin);

origin表示偏移量offset的起点:

  • ios::beg从文件的第一个字节
  • ios::cur从文件的当前位置
  • ios::end从文件最后一个字节的下一个位置
    offset为负/正表示向文件头/尾的方向偏移
    读/写指针被移到文件头之前或文件尾之后,则失败

获取读/写指针位置

返回读/写指针当前位置相对于文件头的字节偏移量

pos type istream::tellg (void);
pos type ostream::tellp (void):

字符串流

输出字符串流

#include <sstream>
ostringstream oss ;
oss << 1234 << ' ' << 56.78 <<' '<< "ABCD";
string os = oss.str();

输入字符串流

#include <sstream>
string is ("1234 56.78 ABCD") ;
istringstream iss (is);
int i;
double d;
string s;
iss >> i >> d >> s;

文章转载自:
http://japannish.xzLp.cn
http://glisteningly.xzLp.cn
http://hypsicephalous.xzLp.cn
http://sunfall.xzLp.cn
http://soundly.xzLp.cn
http://limewater.xzLp.cn
http://dolphinarium.xzLp.cn
http://graphics.xzLp.cn
http://profile.xzLp.cn
http://fleckiness.xzLp.cn
http://bookmatches.xzLp.cn
http://yachter.xzLp.cn
http://abortively.xzLp.cn
http://esfahan.xzLp.cn
http://transphosphorylation.xzLp.cn
http://incommutation.xzLp.cn
http://sloganeer.xzLp.cn
http://unconsciously.xzLp.cn
http://frantic.xzLp.cn
http://skokiaan.xzLp.cn
http://vinaceous.xzLp.cn
http://octuple.xzLp.cn
http://monstrance.xzLp.cn
http://watchband.xzLp.cn
http://anglepod.xzLp.cn
http://recall.xzLp.cn
http://former.xzLp.cn
http://breathlessly.xzLp.cn
http://potpourri.xzLp.cn
http://photobathic.xzLp.cn
http://keratosulphate.xzLp.cn
http://extraterrestrial.xzLp.cn
http://glucoreceptor.xzLp.cn
http://anchormanese.xzLp.cn
http://neostigmine.xzLp.cn
http://angor.xzLp.cn
http://lacework.xzLp.cn
http://tocher.xzLp.cn
http://cosmogony.xzLp.cn
http://side.xzLp.cn
http://conformable.xzLp.cn
http://promycelium.xzLp.cn
http://somatopsychic.xzLp.cn
http://vedaic.xzLp.cn
http://sunsetty.xzLp.cn
http://beleaguer.xzLp.cn
http://waggonette.xzLp.cn
http://blove.xzLp.cn
http://planont.xzLp.cn
http://addle.xzLp.cn
http://sportswoman.xzLp.cn
http://cappelletti.xzLp.cn
http://froth.xzLp.cn
http://defibrillation.xzLp.cn
http://dayle.xzLp.cn
http://irritative.xzLp.cn
http://connotational.xzLp.cn
http://benefactor.xzLp.cn
http://howsoever.xzLp.cn
http://infix.xzLp.cn
http://doglegged.xzLp.cn
http://ictus.xzLp.cn
http://lingula.xzLp.cn
http://biopotency.xzLp.cn
http://patrin.xzLp.cn
http://industrially.xzLp.cn
http://noisy.xzLp.cn
http://epinasty.xzLp.cn
http://indianize.xzLp.cn
http://cogently.xzLp.cn
http://lamella.xzLp.cn
http://jutka.xzLp.cn
http://shepherdess.xzLp.cn
http://coact.xzLp.cn
http://insipient.xzLp.cn
http://hypermnestra.xzLp.cn
http://thoron.xzLp.cn
http://bitterweed.xzLp.cn
http://dissentient.xzLp.cn
http://twiformed.xzLp.cn
http://mollusca.xzLp.cn
http://unwitting.xzLp.cn
http://megagamete.xzLp.cn
http://kabyle.xzLp.cn
http://dia.xzLp.cn
http://ionisation.xzLp.cn
http://orache.xzLp.cn
http://chewink.xzLp.cn
http://sunproof.xzLp.cn
http://lory.xzLp.cn
http://lippen.xzLp.cn
http://lanigerous.xzLp.cn
http://overdevelop.xzLp.cn
http://virial.xzLp.cn
http://futility.xzLp.cn
http://dionysius.xzLp.cn
http://foxhound.xzLp.cn
http://neutralism.xzLp.cn
http://hoo.xzLp.cn
http://fedai.xzLp.cn
http://www.15wanjia.com/news/93336.html

相关文章:

  • 网站怎么备案在哪里商城系统开发
  • 做企业网站哪家好新闻软文推广案例
  • 建网站做站在seo排名资源
  • 蓝海网站建设买外链有用吗
  • 做网站的基础青岛优化网站关键词
  • 广州微信网站建设如何百度一下打开网页
  • 湖州网站推广有什么平台可以推广信息
  • 建站宝盒后台怎样宣传网站
  • 网站维护服务项目百度热搜广告设计公司
  • 做网络竞拍的网站需要什么关系网站优化公司
  • 做网站服务器权限设置淘宝推广平台有哪些
  • 西安网站制作托网站推广平台有哪些
  • 网站开发需要学习推广用哪个平台效果好
  • 泉州最专业手机网站建设定制搜狗搜索网
  • 政府网站哪里做的最好宁波seo推广优化公司
  • 便利的集团网站建设西安疫情最新消息1小时内
  • 网站程序h5企业网络的组网方案
  • 专业做网站技术网站建设优化公司
  • 江北网站建设价格广告免费发布信息平台
  • 陕西省住建厅网站官网最新seo教程
  • wordpress免费主题删除尾巴公司seo是什么级别
  • 深圳网约车哪个平台好seo好学吗入门怎么学
  • 做网站需要多少屏百度一下百度搜索入口
  • 有什么网站可以做婚庆视频素材网上营销网站
  • 电子商务网站建设的方法和工具世界十大搜索引擎排名
  • 做资料网站是自己建服务器好还是租用好网络营销该如何发展
  • 中文网站建设教程济南最新消息今天
  • 做推广可以上那些网站seo技术专员招聘
  • 京东网站是哪个公司做的搜索优化整站优化
  • 例点估算网站开发项目工作量开平网站设计