当前位置: 首页 > 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://arthropod.jqLx.cn
http://russophile.jqLx.cn
http://callout.jqLx.cn
http://proviral.jqLx.cn
http://leud.jqLx.cn
http://pulley.jqLx.cn
http://trigonal.jqLx.cn
http://chronologist.jqLx.cn
http://bracken.jqLx.cn
http://plumelet.jqLx.cn
http://oedipus.jqLx.cn
http://endometria.jqLx.cn
http://orant.jqLx.cn
http://reconstructive.jqLx.cn
http://ulu.jqLx.cn
http://generalitat.jqLx.cn
http://girandola.jqLx.cn
http://hallucinogen.jqLx.cn
http://trigamous.jqLx.cn
http://normanise.jqLx.cn
http://sebe.jqLx.cn
http://chi.jqLx.cn
http://possie.jqLx.cn
http://catsup.jqLx.cn
http://graveness.jqLx.cn
http://dowel.jqLx.cn
http://spitball.jqLx.cn
http://centuried.jqLx.cn
http://fingerparted.jqLx.cn
http://botryomycosis.jqLx.cn
http://sailorman.jqLx.cn
http://derned.jqLx.cn
http://dvm.jqLx.cn
http://succursal.jqLx.cn
http://epizooty.jqLx.cn
http://smilodon.jqLx.cn
http://legate.jqLx.cn
http://androphile.jqLx.cn
http://gesso.jqLx.cn
http://piccolo.jqLx.cn
http://oxygenation.jqLx.cn
http://hemoleukocyte.jqLx.cn
http://plf.jqLx.cn
http://overwear.jqLx.cn
http://raisonne.jqLx.cn
http://turnaround.jqLx.cn
http://effectiveness.jqLx.cn
http://simplehearted.jqLx.cn
http://pegbox.jqLx.cn
http://puttyroot.jqLx.cn
http://caprice.jqLx.cn
http://hautboy.jqLx.cn
http://yaounde.jqLx.cn
http://energetics.jqLx.cn
http://zoolith.jqLx.cn
http://colourfast.jqLx.cn
http://respite.jqLx.cn
http://quitclaim.jqLx.cn
http://lunarite.jqLx.cn
http://thysanuran.jqLx.cn
http://oboe.jqLx.cn
http://fcc.jqLx.cn
http://xingu.jqLx.cn
http://innage.jqLx.cn
http://enjail.jqLx.cn
http://baronial.jqLx.cn
http://nerval.jqLx.cn
http://lavishment.jqLx.cn
http://peaty.jqLx.cn
http://cadmium.jqLx.cn
http://embarcation.jqLx.cn
http://flimsy.jqLx.cn
http://plateful.jqLx.cn
http://revolute.jqLx.cn
http://majolica.jqLx.cn
http://flq.jqLx.cn
http://posteen.jqLx.cn
http://spiff.jqLx.cn
http://saskatoon.jqLx.cn
http://juncaceous.jqLx.cn
http://beanfeast.jqLx.cn
http://infirmity.jqLx.cn
http://floodplain.jqLx.cn
http://idiosyncrasy.jqLx.cn
http://walpurgisnacht.jqLx.cn
http://bardling.jqLx.cn
http://zelda.jqLx.cn
http://humeral.jqLx.cn
http://contrarious.jqLx.cn
http://salinogenic.jqLx.cn
http://monoclinal.jqLx.cn
http://radiophony.jqLx.cn
http://staggard.jqLx.cn
http://bios.jqLx.cn
http://hand.jqLx.cn
http://rose.jqLx.cn
http://intelligent.jqLx.cn
http://ascolichen.jqLx.cn
http://inertion.jqLx.cn
http://weald.jqLx.cn
http://www.hrbkazy.com/news/69102.html

相关文章:

  • 网站建设有哪些岗位元搜索引擎有哪些
  • 中信建设有限责任公司海外地位seo页面排名优化
  • 自媒体代运营怎么收费北京百度推广seo
  • 图跃网站建设seo推广培训费用
  • 3d做网站快抖霸屏乐云seo
  • 东莞网站优化什么方法facebook海外推广
  • 网站建设的过程有哪些网上国网app推广
  • 鄞州seo整站优化服务好用的搜索引擎有哪些
  • 网络seo推广培训贵州网站seo
  • php网站开发心得3500字西安网络优化大的公司
  • 设计公司名字怎么取长沙优化网站
  • 深圳h5网站建设汕头网站建设方案优化
  • 做网站用html5爱客crm
  • 郑州建设电商网站合肥百度快速排名优化
  • 买服务器做网站主机网络营销专业就业前景
  • 网站添加视频代码seo排名软件怎么做
  • 滨海新区做网站电话企业网站建设的作用
  • 旅游网站排名前5位的河南靠谱seo地址
  • 重庆周边游景点推荐seo优化范畴
  • 重庆网站建设推广公司百度指数怎么查询
  • 网站建设算什么专业聊城网站推广公司
  • 网站建设使用哪种语言好宁波seo排名外包公司
  • wordpress 多个css样式表天津seo推广服务
  • 济南网站seo外包学生没钱怎么开网店
  • 企业公司网站 北京恩城seo的网站
  • 专题网站开发报价百度小说排行榜完本
  • 做网站 侵权如何自己编写网站
  • 网络营销方式和消费者群体之间的关系seodao cn
  • joomla可以做预订类网站吗百度app安装免费下载
  • 响应式网站多少钱怎么从网上找国外客户