项目一:获取时间不用std标准库std::chrono:high_resolution_clock, 获取时间用TSCNS的实例化后的函数.rdns(),利用午夜时间戳计算当前时间。
利用fmt库的格式化输出打印当前时间。
fmtlog采用轮循,fmtlog::poll轮循日志队列,从日志队列中取出消息并将其写入输出。
项目二:利用pollnet开源项目,分为两个部分,第一个部分进行数据结构转换,定义读表的类,
// CSV 文件解析类
class CsvReader {
public:
CsvReader() = default;
void load_from_file(const char* filepath) {
file_.open(filepath);
if (!file_.is_open()) {
throw std::runtime_error("Failed to open CSV file.");
}
}
bool next_row(std::vector<std::string>& row) {
row.clear();
std::string line;
if (std::getline(file_, line)) {
std::stringstream line_stream(line);
std::string cell;
while (std::getline(line_stream, cell, ',')) {
row.push_back(cell);
}
return true;
}
return false;
}
private:
std::ifstream file_;
};
转换时进行表头匹配,注意需要去掉表头的前后空格:
// 去掉前后空格
value.erase(0, value.find_first_not_of(" \t\n\r"));
value.erase(value.find_last_not_of(" \t\n\r") + 1);
转换时可以用stoi和stoull,还有stoll
std::stoi
:转换为int
。std::stoll
:转换为long long
,它是带符号整数,可以表示更大范围的正负整数,通常其范围为-9223372036854775808
到9223372036854775807
(具体范围取决于系统)。std::stoull
:转换为unsigned long long
,无符号整数,不允许负值,通常范围是0
到18446744073709551615
。
在转化时间的时候要特别注意,因为从表格中读出来的时间日期格式不一定相同 需要分别处理。
一个vector存储一行数据,一个list存储多个vector数据,用push_back将vector放入l