Ai
1 Star 0 Fork 0

kzy111/Linux

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Init.hpp 1.15 KB
一键复制 编辑 原始数据 按行查看 历史
kzy111 提交于 2024-06-15 16:42 +08:00 . tcp
#pragma once
#include <iostream>
#include <string>
#include <fstream>
#include <unordered_map>
#include "Log.hpp"
const std::string dictname = "./dict.txt";
const std::string sep = ":";
//yellow:黄色...
static bool Split(std::string &s, std::string *part1, std::string *part2)
{
auto pos = s.find(sep);
if(pos == std::string::npos) return false;
*part1 = s.substr(0, pos);
*part2 = s.substr(pos+1);
return true;
}
class Init
{
public:
Init()
{
std::ifstream in(dictname);
if(!in.is_open())
{
lg(Fatal, "ifstream open %s error", dictname.c_str());
exit(1);
}
std::string line;
while(std::getline(in, line))
{
std::string part1, part2;
Split(line, &part1, &part2);
dict.insert({part1, part2});
}
in.close();
}
std::string translation(const std::string &key)
{
auto iter = dict.find(key);
if(iter == dict.end()) return "Unknow";
else return iter->second;
}
private:
std::unordered_map<std::string, std::string> dict;
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/kzy111/linux.git
git@gitee.com:kzy111/linux.git
kzy111
linux
Linux
master

搜索帮助