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

asp.net企业网站管理系统国内疫情最新消息

asp.net企业网站管理系统,国内疫情最新消息,剑三做月饼活动网站,乐清新闻最新消息视频在学习C文件流控制时(链接)我们知道C有一个标准库fstream 该库定义了三个数据类型 ofstream ifstream 和 fstream 在练习相应的案例时,seekg() 函数掌握的不是很好,后经过多次尝试,可以正常调用了 代码如下&#xff1…

在学习C++文件流控制时(链接)我们知道C++有一个标准库fstream
该库定义了三个数据类型 ofstream ifstream 和 fstream
在练习相应的案例时,seekg() 函数掌握的不是很好,后经过多次尝试,可以正常调用了

代码如下:

#include <fstream>
#include <iostream>
using namespace std;int main()
{char data[100]; 以写模式打开文件//ofstream outfile;//outfile.open("new.out");//cout << "Writing to the file" << endl;//cout << "Enter your name: ";//cin.getline(data, 100); 向文件写入用户输入的数据//outfile << data << endl;//cout << "Enter your name: ";//cin.getline(data, 100); 向文件写入用户输入的数据//outfile << data << endl;//cout << "Enter your name: ";//cin.getline(data, 100); 向文件写入用户输入的数据//outfile << data << endl;//cout << "Enter your name: ";//cin.getline(data, 100); 向文件写入用户输入的数据//outfile << data << endl;//cout << "Enter your name: ";//cin.getline(data, 100); 向文件写入用户输入的数据//outfile << data << 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();char ch;// 以读模式打开文件fstream infile;infile.open("new.out");cout << "Reading from the file" << endl;infile >> data;// 在屏幕上写入数据cout << data << endl;cout << infile.tellg() << endl;// 再次从文件读取数据,并显示它infile >> data;cout << data << endl;cout << "a line" << endl;cout << infile.tellg() << endl;infile.get(ch);cout << ch << endl;infile.seekg(0L, ios::cur);cout << infile.tellg() << endl;infile.get(ch);cout << ch << endl;6infile.seekg(-1L, ios::cur);cout << infile.tellg() << endl;infile.get(ch);cout << ch << endl;infile.seekg(-1L, ios::cur);cout << infile.tellg() << endl;infile.get(ch);cout << ch << endl;infile.seekg(-2L, ios::cur);cout << infile.tellg() << endl;infile.get(ch);cout << ch << endl;//cout << infile.rdbuf() << endl;cout << "a line" << endl;//1111infile.seekg(-3, ios::end);infile.get(ch);cout << ch << endl;//6infile.seekg(-8, ios::end);//infile.get(ch);//cout << ch << endl;cout << infile.rdbuf() ;//3infile.seekg(0, ios::beg);infile.get(ch);cout << ch << endl;cout << 'a line' << endl;// 关闭打开的文件infile.close();return 0;
}

这段代码前半段负责写入程序,后半段从文件中读取数据
需要注意以下几点:

  • 在读取文件时,实例化 fstream 和 ifstream 均可
  • 使用 infile.tellg() 追踪文件指针的位置
  • 使用 cout << infile.rdbuf() ; 输出指针所在处的整个单词
  • ios::cur 在当前指针位置处跳跃
  • ios::beg 从头开始跳跃
  • ios::end 从后往前遍历
  • 使用 ios::end 时,如果想向前遍历,需要输入负的步长
  • infile >> data; 整行输出
    关于 ios::cur 指针部分还是有点迷糊,可以先通过 infile.tellg() 考察指针移动情况,需要用到的时候再深入学习。
http://www.hkea.cn/news/474821/

相关文章:

  • 西安做网站收费价格网站流量监控
  • 福州网站制作有限公司南京疫情最新情况
  • 国外品牌设计网站天津疫情最新消息
  • 宁波有做网站的地方吗seo报价单
  • 深圳企业网站开发中国法律服务网app最新下载
  • 大连企业网站建站国外域名注册网站
  • 站长工具seo综合查询权重百度在线搜索
  • 伊犁网站建设评价怎样才能上百度
  • 房地产网站建设方案百度实名认证
  • 做外贸可以在哪些网站注册网络项目免费的资源网
  • 中国建设银行信用卡网站首页青岛关键词优化平台
  • 阿里云网站建设考试题目长沙网站推广服务公司
  • 甘肃建设项目审批权限网站俄罗斯搜索引擎yandex官网入口
  • 网站建设公司新员工培训ppt模板百度热门搜索排行榜
  • 仿魔客吧网站模板网址大全是ie浏览器吗
  • 网站产品后台界面怎么做湖南关键词排名推广
  • 网站数据每隔几秒切换怎么做的湖南百度seo排名点击软件
  • 网站制作先学什么百度新闻下载安装
  • 河南省网站建设哪家好免费观看行情软件网站进入
  • 粘合剂东莞网站建设体育热点新闻
  • 百度网站排名关键词整站优化培训网站建设
  • 网络平台代理seo外包 杭州
  • 东方头条网站源码免费推广软件工具
  • 北京网站建设公司分享网站改版注意事项流程优化四个方法
  • 案例学 网页设计与网站建设手机百度seo快速排名
  • 江门网站建设总部电话产品推广渠道有哪些
  • 网站建设全攻略站长之家ping检测
  • 导航网站 cmsgoogle chrome谷歌浏览器
  • wordpress看其他人博客优化师是做什么的
  • 现在哪个网站还做白拿2021小说排行榜百度风云榜