解析一个非常简单的配置文件
Parsing a Very Simply Config File
我正在用c++编写一个OBDII阅读库/应用程序。通过发送一个简单的字符串命令从汽车的计算机中检索数据,然后将结果传递给特定于每个参数的函数。
我想读取所有我想要的命令的配置文件,像这样的东西:
Name, Command, function
Engine RPM, 010C, ((256*A)+B)/4
Speed, 010D, A
基本上,非常简单,所有的数据都需要作为字符串读入。有人能推荐一个简单的库吗?我的目标是g++和/或Linux上的Clang。
您可以使用std::ifstream逐行读取,并使用boost::split按,
分割行。
示例代码:
您可以检查令牌大小以检查所加载文件的完整性。
#include <fstream>
#include <vector>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>
int main(int argc, char* argv[]) {
std::ifstream ifs("e:\save.txt");
std::string line;
std::vector<std::string> tokens;
while (std::getline(ifs, line)) {
boost::split(tokens, line, boost::is_any_of(","));
if (line.empty())
continue;
for (const auto& t : tokens) {
std::cout << t << std::endl;
}
}
return 0;
}
如果你不想实现,你也可以使用String Toolkit Library。文档
相关文章:
- 一个非常简单的win32套接字代码,但工作错误
- 无法使用crfsuite的C++ API编译一个非常简单的Tagger示例
- C++中一个非常简单的枚举类错误
- C / C++链接问题与非常简单的设置
- 理解循环,非常简单
- 我正在写一个非常简单的字母评分系统,if语句是最有效的吗?
- 非常简单的C 文本冒险的代码结构
- 为什么在 v8 中运行嵌入在 c++ 中的非常简单的脚本会占用内存?
- boost/asio:非常简单的聊天服务器无法访问收到的消息
- DirectX 11 - 如何创建非常简单的 2D 纹理
- 如果将功能的非常简单的定义移动到.cpp,则编译时间的减少是多少
- 在C 中编写一个非常简单的事件类
- Winapi中使用ListBox的非常简单的示例
- 在使用Qt Creator创建一个非常简单的项目时,在Qt中遇到"segmentation fault"
- 非常简单C++基本代码
- 需要非常简单的循环C++帮助
- C++非常简单的未解决外部
- Clang编译器错误,适用于非常简单的程序
- 非常简单的 x64 组装/C++应用程序中未解决的外部错误
- 错误:在非常简单的示例中,预期的构造函数、析构函数或类型转换