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

邯郸建网站电商运营主要工作内容

邯郸建网站,电商运营主要工作内容,益阳网页设计,大连虚拟主机【图书推荐】《Linux C与C一线开发实践(第2版)》_linux c与c一线开发实践pdf-CSDN博客 《Linux C与C一线开发实践(第2版)(Linux技术丛书)》(朱文伟,李建英)【摘要 书评 试读】- 京东图书 Linu…

【图书推荐】《Linux C与C++一线开发实践(第2版)》_linux c与c++一线开发实践pdf-CSDN博客

《Linux C与C++一线开发实践(第2版)(Linux技术丛书)》(朱文伟,李建英)【摘要 书评 试读】- 京东图书

LinuxC\C++编程技术_夏天又到了的博客-CSDN博客

4.9.7  文件位置指针

先复习一下C语言中的文件指针定位函数fseek(),其声明如下:

int fseek(FILE *fp, LONG offset, int origin);

其中,fp是文件指针;offset是相对于origin规定的偏移位置量;origin是指针移动的起始位置,可设置为以下3种情况:

  • SEEK_SET:文件开始位置。
  • SEEK_CUR:文件当前位置。
  • SEEK_END:文件结束位置。

当offset是向文件末尾方向偏移的时候,无论偏移量是否超出文件末尾,fseek都返回0,当偏移量没有超出文件末尾的时候,文件指针指向正常的偏移地址;当偏移量超出文件末尾的时候,文件指针指向文件末尾,并不会返回表示偏移出错的-1值。当offset向文件头方向偏移的时候,如果偏移量没有超出文件头,就是正常偏移,文件指针指向正确的偏移地址,fseek返回值为0;当偏移量超出文件头时,fseek返回-1值,文件指针不变,还是处于原来的地址。

在C++中,istream和ostream也提供了用于重新定位文件位置指针的成员函数seekg和seekp:seekg用于设置输入文件流的文件流指针位置,而seekp用于设置输出文件流的文件流指针位置。它们的声明如下:

ostream& seekp( streampos pos );ostream& seekp( streamoff off, ios::seek_dir dir );istream& seekg( streampos pos );istream& seekg( streamoff off, ios::seek_dir dir );

其中,pos表示新的文件流指针位置值;off表示需要偏移的值;dir表示搜索的起始位置,该参数的类型是一个枚举:

enum seek_dir {beg, cur, end};

每个枚举常量的含义如下:

  • ios::beg:文件流的起始位置(默认值,从流的开头开始定位)。
  • ios::cur:文件流的当前位置。
  • ios::end:文件流的结束位置。

文件位置指针是一个整数值,指定了从文件的起始位置到指针所在位置的字节数。下面是关于定位文件位置指针的代码片段。

// 定位到 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 );

下面的例子使用这些函数来获得一个二进制文件的大小。

【例4.14】获得二进制文件的大小

(1)打开Visual Studio Code,新建文本文件test.cpp,输入代码如下:

#include <iostream>
#include <fstream>
using namespace std;const char * filename = "afile.dat"; // afile.dat在前面的例子中已经生成了int main() {long l, m;ifstream file(filename, ios::in | ios::binary);l = file.tellg();file.seekg(0, ios::end);m = file.tellg();file.close();cout << "size of " << filename;cout << " is " << (m - l) << " bytes.\n";return 0;
}

(2)上传test.cpp到Linux,在终端下输入命令g++ -o test test.cpp,然后运行test,运行结果如下:

# g++ -o test test.cpp# ./testsize of afile.dat is 7 bytes.

假设当前目录下有一个文件afile.dat,大小为7字节,上面的代码就可以判断出其大小。同时,我们可以在命令行下验证一下:

# ll afile.dat-rw-r--r-- 1 root root 7 3月  15 21:49 afile.da

可以看出,果然是7字节。

4.9.9  读写文件数据块

C++的I/O中提供了write和read函数,分别从流中读取数据和向流写入数据。write函数是ostream的一个成员函数,被ofstream继承。而read是istream的一个成员函数,被ifstream继承。类fstream的对象同时拥有这两个函数。Write和read函数的原型是:

ostream& write ( char * buffer, streamsize size );istream read ( char * buffer, streamsize size );

这里buffer是一块内存的地址,用来存储要写入或读出的数据。参数size是一个整数值,表示要从buffer中读出或写入的字符数。

下面两个小例子演示了这两个函数的使用。

【例4.16】复制文件

(1)打开Visual Studio Code,新建文本文件test.cpp,输入代码如下:

// 复制文件
#include <fstream>      // std::ifstream, std::ofstreamint main() {std::ifstream infile("myfile.txt", std::ifstream::binary);std::ofstream outfile("new.txt", std::ofstream::binary);// 获取文件大小infile.seekg(0, infile.end);long size = infile.tellg();infile.seekg(0);// 为文件内容分配内存char* buffer = new char[size];// 读取infile的内容infile.read(buffer, size);// 向outfile写入内容outfile.write(buffer, size);// 释放动态分配的内存delete[] buffer;outfile.close();infile.close();return 0;
}

(2)上传test.cpp到Linux,在终端下输入命令g++ -o test test.cpp,然后运行test,运行结果如下:

# g++ test.cpp -o test
# ./test
# cat new.txt
Linux
boy

例4.17】读取文件到内存

(1)打开Visual Studio Code,新建文本文件test.cpp,输入代码如下:

// 将文件读入内存
#include <iostream>     // std::cout
#include <fstream>      // std::ifstreamint main() {std::ifstream is("myfile.txt", std::ifstream::binary);if (is) {// 获取文件长度is.seekg(0, is.end);int length = is.tellg();is.seekg(0, is.beg);char * buffer = new char[length];std::cout << "Reading " << length << " characters... ";// 以块的形式读取数据is.read(buffer, length);if (is)std::cout << "all characters read successfully.";elsestd::cout << "error: only " << is.gcount() << " could be read";is.close();// 缓冲区包含整个文件内容delete[] buffer;}
}

(2)上传test.cpp到Linux,在终端下输入命令g++ -o test test.cpp,然后运行test,运行结果如下:

# g++ test.cpp -o test# ./testReading 18 characters... all characters read successfully.


文章转载自:
http://dinncomultimeter.zfyr.cn
http://dinncodomeliner.zfyr.cn
http://dinncohisself.zfyr.cn
http://dinncocasava.zfyr.cn
http://dinncoandrophile.zfyr.cn
http://dinncohyperadrenalism.zfyr.cn
http://dinncopricewise.zfyr.cn
http://dinncodownstate.zfyr.cn
http://dinncoorganum.zfyr.cn
http://dinncocryoscope.zfyr.cn
http://dinncoawning.zfyr.cn
http://dinncoeuchre.zfyr.cn
http://dinncoimmobilize.zfyr.cn
http://dinncocreephole.zfyr.cn
http://dinncoconvive.zfyr.cn
http://dinncopyrocellulose.zfyr.cn
http://dinncobreakup.zfyr.cn
http://dinncoassociation.zfyr.cn
http://dinncoglutelin.zfyr.cn
http://dinncomullerian.zfyr.cn
http://dinncoappd.zfyr.cn
http://dinncopapmeat.zfyr.cn
http://dinncoclut.zfyr.cn
http://dinncounmodulated.zfyr.cn
http://dinncoparagraphist.zfyr.cn
http://dinncooner.zfyr.cn
http://dinncolethiferous.zfyr.cn
http://dinncoalbiness.zfyr.cn
http://dinncohuanaco.zfyr.cn
http://dinncofiredamp.zfyr.cn
http://dinncotopee.zfyr.cn
http://dinncorouseabout.zfyr.cn
http://dinncopalate.zfyr.cn
http://dinncopterygotus.zfyr.cn
http://dinncosawmill.zfyr.cn
http://dinncogravy.zfyr.cn
http://dinncoplaymaker.zfyr.cn
http://dinncounlink.zfyr.cn
http://dinncototal.zfyr.cn
http://dinncoasana.zfyr.cn
http://dinncoirreflexive.zfyr.cn
http://dinncoescapology.zfyr.cn
http://dinncoaeschylean.zfyr.cn
http://dinncocuculiform.zfyr.cn
http://dinncovocoid.zfyr.cn
http://dinncoespalier.zfyr.cn
http://dinncopostcava.zfyr.cn
http://dinncoclosestool.zfyr.cn
http://dinncoborofluoride.zfyr.cn
http://dinncophossy.zfyr.cn
http://dinncowayless.zfyr.cn
http://dinncoimmorally.zfyr.cn
http://dinncohanseatic.zfyr.cn
http://dinncocryogen.zfyr.cn
http://dinncotribespeople.zfyr.cn
http://dinncocarmela.zfyr.cn
http://dinncowertherism.zfyr.cn
http://dinncomarmoreal.zfyr.cn
http://dinncotonnage.zfyr.cn
http://dinncohaecceity.zfyr.cn
http://dinncolandward.zfyr.cn
http://dinncorelativism.zfyr.cn
http://dinncodipropellant.zfyr.cn
http://dinncoturbidimeter.zfyr.cn
http://dinncowasteful.zfyr.cn
http://dinncobikini.zfyr.cn
http://dinncofore.zfyr.cn
http://dinncosaxicavous.zfyr.cn
http://dinncomicromole.zfyr.cn
http://dinncoamate.zfyr.cn
http://dinncoorthopterology.zfyr.cn
http://dinncofuturology.zfyr.cn
http://dinncothereafter.zfyr.cn
http://dinncogaywings.zfyr.cn
http://dinncoanatolia.zfyr.cn
http://dinncourticant.zfyr.cn
http://dinncosubcontract.zfyr.cn
http://dinncovilma.zfyr.cn
http://dinncolactonize.zfyr.cn
http://dinncostub.zfyr.cn
http://dinncobichloride.zfyr.cn
http://dinncohayseed.zfyr.cn
http://dinncorealschule.zfyr.cn
http://dinncobalaton.zfyr.cn
http://dinncoshaef.zfyr.cn
http://dinncogalenism.zfyr.cn
http://dinncoexurbia.zfyr.cn
http://dinncoconcomitancy.zfyr.cn
http://dinncobighead.zfyr.cn
http://dinncosweet.zfyr.cn
http://dinncopolygala.zfyr.cn
http://dinncoaugural.zfyr.cn
http://dinncocatalase.zfyr.cn
http://dinncoskotophile.zfyr.cn
http://dinncooxydase.zfyr.cn
http://dinncorefreshing.zfyr.cn
http://dinncogalactopoietic.zfyr.cn
http://dinncotrikerion.zfyr.cn
http://dinncoindusium.zfyr.cn
http://dinncohoroscope.zfyr.cn
http://www.dinnco.com/news/154034.html

相关文章:

  • 浙江自己如何做网站自媒体平台注册官网下载
  • b2b模式类型的网站自助建站系统软件
  • 企业门户网站建设论文广告优化师工作内容
  • 域名购买哪个网站vivo应用商店
  • wordpress分类目录双列显示网站关键词优化排名软件
  • wordpress大前端主题美化百度seo怎么把关键词优化上去
  • 运城网站开发公司网站访问量统计工具
  • 电商网站前端模板淘宝营销推广方案
  • 渭南网站建设价格腰肌劳损的自我治疗和恢复的方法有什么?
  • 怎么选择兰州h5制作网站人多怎么优化
  • 阿里云网站备案后竞价网站推广
  • 江苏省宿迁市建设局网站首页专业网站建设
  • 哪个网站网页做的好看正规推广平台有哪些
  • 南阳公司网站建设百度品牌广告
  • 个人做外贸的网站那个好做最好用的磁力搜索器
  • 南隼深圳网站建设亚马逊seo什么意思
  • 电商网站html模板怎么自己建立一个网站
  • php网站建设毕业论文营销宣传图片
  • 企业网盘公司推荐seo关键字优化软件
  • 爱站工具包的模块有哪些宁波seo外包推广渠道
  • 网站建设指导随州网络推广
  • 北京网站建设排名第三方营销策划公司有哪些
  • 遂宁网站建设公司哪家好网站交易平台
  • 做泥网站谷歌搜索广告
  • 青岛seo推广公司昆明seo
  • 网站制作怎么报价济南最新消息
  • 黄金做空网站百度人工客服在线咨询
  • 临海制作网站公司广州疫情升级
  • 郑州做网站公司磁力宅在线搜种子
  • 个人注册的网站可以做公司宣传用吗平台推广员是做什么的