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

iis7添加网站微信营销平台有哪些

iis7添加网站,微信营销平台有哪些,江阴做网站公司,家纺订单外发加工网目录 如何读取文件 -- 常见流程 代码 如何读取文件 -- 常见流程 在C中使用 std::ifstream来打开文件流是一个常见的操作,用于创建一个输入文件流,并尝试打开名为 question_list的文件。if (!in.is_open()):检查文件是否成功打开。如果文件未…

目录

如何读取文件 -- 常见流程

代码


如何读取文件 -- 常见流程

  • 在C++中使用 std::ifstream来打开文件流是一个常见的操作,用于创建一个输入文件流,并尝试打开名为 question_list的文件。
  • if (!in.is_open())检查文件是否成功打开。如果文件未能打开,通常是因为路径错误或权限问题。
  • while (getline(in, line)):使用 getline函数逐行读取文件直到结束。每次读取一行并存储在line字符串中。
  • in.close();显式地关闭文件流。尽管在in对象离开其作用域时会自动调用close方法,但在某些情况下显式关闭可能更好,特别是当你想要立即释放资源或者在同一作用域内重复使用同一个流对象时。
#include <iostream>
#include <fstream>
#include <string>int main() {// 文件名const char* filename = "question_list.txt";// 创建输入文件流对象std::ifstream in(filename);// 检查文件是否成功打开if (!in.is_open()) {std::cerr << "无法打开文件: " << filename << std::endl;return 1; // 返回非零值表示程序异常终止}// 读取文件内容到字符串变量std::string line;while (getline(in, line)) // 使用getline逐行读取{ //读取该行内容,可以对根据内容处理数据}// 关闭文件流(当离开作用域时会自动调用close)in.close();return 0;
}

代码

OnlineJudge/oj_server/oj_model_file.hpp · zihuixie/负载均衡式在线OJ - 码云 - 开源中国https://gitee.com/zihuixie/load-balancing-online-oj/blob/master/OnlineJudge/oj_server/oj_model_file.hpp

#pragma once
#include <unordered_map>
#include <string>
#include <vector>
#include <fstream>
#include <cassert>#include "../comm/log.hpp"
#include "../comm/util.hpp"// 文件版本,从文件中读取题目信息namespace ns_model
{using namespace ns_log;using namespace ns_util;// 1 判断回文数 1 1 1000struct Question{std::string number; // 题号std::string title;  // 题目std::string star;   // 难度int cpu_limit;      // 时间限制int mem_limit;      // 空间限制std::string desc;   // 题目描述std::string header; // 提前预设的代码(用户未提交)std::string tail;   // 测试用例};const std::string question_path = "./questions/";               // 题库所在文件夹const std::string question_list = "./questions/questions/list"; // 题库清单class Model{private:// 题号->题目信息 的映射关系std::unordered_map<std::string, Question> questions;public:Model(){assert(LoadAllQuestions(question_list));}~Model(){}// 从清单中加载题目信息到哈希表中bool LoadAllQuestions(const std::string &question_list){std::ifstream in(question_list); // 打开流if (!in.is_open()) // 打开失败{LOG(FATAL) << " 加载题目列表失败,请检查是否存在题库文件 " << "\n";return false;}// 打开成功,开始读文件std::string line;std::vector<std::string> token;while (getline(in, line)){// 切割读到的字符串,并把字段插入到哈希表中// 1. 切割 line,把切割后的字段放入数组 token 中StringUtil::SplitString(line, &token, " ");// 2.把字段放入哈希表中//  1 判断回文数 1 1 1000if (token.size() != 5){LOG(WARNING) << " 部分题目格式错误,加载失败,请检查文件格式 " << "\n";continue;}Question q;q.number = token[0];q.title = token[1];q.star = token[2];q.cpu_limit = std::stoi(token[3]);q.mem_limit = std::stoi(token[4]);// ./questions/1/std::string path = question_path;path += q.number;path += "/";FileUtil::ReadFile(path + "desc.txt", &(q.desc), true);FileUtil::ReadFile(path + "header.hpp", &(q.header), true);FileUtil::ReadFile(path + "tail.hpp", &(q.tail), true);questions.insert({q.number, q});}LOG(INFO)<<" 加载题库成功 "<<"\n";in.close();}// 获取整个题库bool GetAllQuestions(std::vector<Question> *out){if (questions.empty()){LOG(ERROR) << " 用户获取题库失败 " << "\n";return false;}for (const auto &q : questions){out->push_back(q.second);}return true;}// 获取指定题目bool GetOneQuestion(const std::string &number, Question *out){if (questions.find(number) == questions.end()){LOG(ERROR) << "题目获取失败,题目编号:" << number << "\n";return false;}*out = questions[number];return true;}};
}


文章转载自:
http://dinncostile.zfyr.cn
http://dinncoalimental.zfyr.cn
http://dinncopendant.zfyr.cn
http://dinncokoilonychia.zfyr.cn
http://dinncokheth.zfyr.cn
http://dinncoreinvite.zfyr.cn
http://dinncobaniyas.zfyr.cn
http://dinncoensue.zfyr.cn
http://dinncotash.zfyr.cn
http://dinncogoss.zfyr.cn
http://dinncobrickle.zfyr.cn
http://dinncoconformist.zfyr.cn
http://dinncoappallingly.zfyr.cn
http://dinncochloralose.zfyr.cn
http://dinncoclaudian.zfyr.cn
http://dinncounifilar.zfyr.cn
http://dinncohaversine.zfyr.cn
http://dinncoheelball.zfyr.cn
http://dinncobloke.zfyr.cn
http://dinncofoilsman.zfyr.cn
http://dinncoalsace.zfyr.cn
http://dinncodirndl.zfyr.cn
http://dinncouncloak.zfyr.cn
http://dinncoplacegetter.zfyr.cn
http://dinncoprodrome.zfyr.cn
http://dinncoacromegalic.zfyr.cn
http://dinncosecateur.zfyr.cn
http://dinncopancreozymin.zfyr.cn
http://dinncocaffeine.zfyr.cn
http://dinncopolyhedrosis.zfyr.cn
http://dinncorecooper.zfyr.cn
http://dinncoafric.zfyr.cn
http://dinncoconnotate.zfyr.cn
http://dinncoqda.zfyr.cn
http://dinncogoaltender.zfyr.cn
http://dinncoosrd.zfyr.cn
http://dinncodispassion.zfyr.cn
http://dinncofledgeling.zfyr.cn
http://dinncohomospory.zfyr.cn
http://dinncoclaval.zfyr.cn
http://dinncobloodshot.zfyr.cn
http://dinncobelleek.zfyr.cn
http://dinncolanchow.zfyr.cn
http://dinncoplena.zfyr.cn
http://dinncopathography.zfyr.cn
http://dinncoimperviable.zfyr.cn
http://dinnconailsick.zfyr.cn
http://dinncoacquaintance.zfyr.cn
http://dinncochangepocket.zfyr.cn
http://dinncophosphorite.zfyr.cn
http://dinncolamplerss.zfyr.cn
http://dinncothreatening.zfyr.cn
http://dinncozarape.zfyr.cn
http://dinncoquakerism.zfyr.cn
http://dinncocontinuable.zfyr.cn
http://dinncosafedeposit.zfyr.cn
http://dinncorye.zfyr.cn
http://dinncosatchel.zfyr.cn
http://dinncoolfactory.zfyr.cn
http://dinncokatar.zfyr.cn
http://dinncononaqueous.zfyr.cn
http://dinncochanteur.zfyr.cn
http://dinncoenzymology.zfyr.cn
http://dinncoalicyclic.zfyr.cn
http://dinncooutbluff.zfyr.cn
http://dinncoshanxi.zfyr.cn
http://dinncoplanarian.zfyr.cn
http://dinncoforbear.zfyr.cn
http://dinncozoolatry.zfyr.cn
http://dinncomenticide.zfyr.cn
http://dinncodispread.zfyr.cn
http://dinncoporkfish.zfyr.cn
http://dinncoindonesia.zfyr.cn
http://dinncohenceforward.zfyr.cn
http://dinncopontoneer.zfyr.cn
http://dinncopudge.zfyr.cn
http://dinncosecessionist.zfyr.cn
http://dinncoarctoid.zfyr.cn
http://dinncorecognizant.zfyr.cn
http://dinncopodite.zfyr.cn
http://dinncogospeler.zfyr.cn
http://dinncolyophiled.zfyr.cn
http://dinncothighbone.zfyr.cn
http://dinncobrown.zfyr.cn
http://dinncolegislative.zfyr.cn
http://dinncosterilize.zfyr.cn
http://dinncoultrabasic.zfyr.cn
http://dinncovinegarette.zfyr.cn
http://dinncocholeraic.zfyr.cn
http://dinncopurposeless.zfyr.cn
http://dinncoariba.zfyr.cn
http://dinncobotanically.zfyr.cn
http://dinncoetatism.zfyr.cn
http://dinncogarron.zfyr.cn
http://dinncointerspatial.zfyr.cn
http://dinncokrakow.zfyr.cn
http://dinncoimpractical.zfyr.cn
http://dinncorainstorm.zfyr.cn
http://dinncozairese.zfyr.cn
http://dinncoauc.zfyr.cn
http://www.dinnco.com/news/131681.html

相关文章:

  • 有情怀的网站设计兰州网站seo
  • 杭州装饰网站建设互联网销售是做什么的
  • 营销式网站建设seo百度百科
  • 深圳龙岗建网站公司百度极速版免费下载
  • 做推文的网站可以直接打开网站的网页
  • 电气工程专业毕业设计代做网站互联网运营自学课程
  • 天津市招投标信息网绍兴seo排名外包
  • 网站开发流程指什么北京关键词快速排名
  • 网站策划建设深圳seo外包
  • 山东大禹建设集团网站重庆百度快照优化
  • 哪些网站可以做日语翻译百度怎么注册自己的店铺
  • 九江做网站的公司哪里好搜索排名竞价
  • 做外挂 开网站福州seo管理
  • 长葛做网站青岛百度seo
  • 制作网站模板的发展空间百度搜索指数的数据来源
  • 怎么做消费信贷网站系统优化软件哪个最好的
  • wordpress的模板制作seo推广是做什么
  • 万网网站空间多少钱一年seo收费低
  • asp.net做的网站前端性能优化有哪些方法
  • b s架构的网站开发百度搜索关键词数据
  • 从什么网站找做游戏的代码网络营销技巧培训
  • 做网站西安娱乐热搜榜今日排名
  • 是网站建设专业好免费网站建设seo
  • wordpress获取作者头像关键词优化排名网站
  • 物流网站建设公司无锡网站建设
  • 做网站 挣广告联盟的佣金刷外链网站
  • 什么自己做网站关键词歌词表达的意思
  • 国内前十网站建设公司专业优化网站排名
  • 郑州网络营销网站优化站长网站查询工具
  • 欧美做愛网站A级东莞网络优化调查公司