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

旅游网站设计及开发wordpress wp_parse_args

旅游网站设计及开发,wordpress wp_parse_args,优化型网站是什么意思,公司备案证查询网站查询系统目录 如何读取文件 -- 常见流程 代码 如何读取文件 -- 常见流程 在C中使用 std::ifstream来打开文件流是一个常见的操作#xff0c;用于创建一个输入文件流#xff0c;并尝试打开名为 question_list的文件。if (!in.is_open())#xff1a;检查文件是否成功打开。如果文件未…目录 如何读取文件 -- 常见流程 代码 如何读取文件 -- 常见流程 在C中使用 std::ifstream来打开文件流是一个常见的操作用于创建一个输入文件流并尝试打开名为 question_list的文件。if (!in.is_open())检查文件是否成功打开。如果文件未能打开通常是因为路径错误或权限问题。while (getline(in, line))使用 getline函数逐行读取文件直到结束。每次读取一行并存储在line字符串中。in.close();显式地关闭文件流。尽管在in对象离开其作用域时会自动调用close方法但在某些情况下显式关闭可能更好特别是当你想要立即释放资源或者在同一作用域内重复使用同一个流对象时。 #include iostream #include fstream #include stringint 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逐行读取{ //读取该行内容可以对根据内容处理数据}// 关闭文件流当离开作用域时会自动调用closein.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_mapstd::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::vectorstd::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::vectorQuestion *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://www.yingshimen.cn/news/115751/

相关文章:

  • 智能建站网站模板怎么关闭网站安全检测
  • 做网站的公司如何运营网络推广文案图片
  • 建设银行银行号查询网站苏州纳米所加工平台
  • 上海市网站开发游戏网址大全有哪些
  • 河海大学学风建设网站产品艺术设计专业
  • 南县中国建设银行网站为什么要做企业官网
  • 优客逸家网站源码商城入口
  • 福田网站制作公司公众号开发 网站开发
  • 网站建设的技术可行性临安做企业网站
  • 大宇网络做网站怎么样品牌网站如何建设
  • 开发网站去哪里学诸暨北京网站制作公司有哪些
  • 制作网站怎么做网站建设多少钱 小江网页设计
  • 房产做网站是什么意思网站建设相关小论文
  • 建设医院网站的重点与难点在于wordpress伪静态 page
  • 谷歌英文网站优化怎么让自己做的网站别人可以访问
  • WordPress数据库和网站文件win7系统如何重装wordpress
  • 做优化网站多少钱互动型网站
  • wap网站建设学什么asp做的网站如何更新
  • 网站开发的关键技术有哪些建设个人网站步骤
  • 管理网站网站建好更新
  • 正规网站建设服务wordpress 站内消息
  • 菜鸟教程网站怎么做农村自建房设计
  • 城口网站建设怎么制作微信小程序游戏
  • 长春网站建设致电吉网传媒优特效网站模板
  • 长春网站优化教程网站开发的课程设置
  • 推进门户网站建设方案做网站用什么域名好
  • 攀枝花移动网站建设php网站开发套模板
  • 电子创意设计网站江油网站网站建设
  • 移动端网站制作模板推广网站建设花费得多少钱
  • 购物车功能网站怎么做的南通网站排名外包