0

I am writing a OBDII reading library / application in C++. Data is retrieved from the car's computer by sending a simple string command, then passing the result through a function specific to each parameter.

I would like to read a config file of all the commands I want, something like this perhaps:

Name, Command, function

Engine RPM, 010C, ((256*A)+B)/4
Speed, 010D, A

Basically, very simple, all data needs to just be read in as a string. Can anyone recommend a good simple library for this? My target is g++ and/ or Clang on Linux if that matters.

lkrasner
  • 112
  • 2
  • 13

1 Answers1

2

You could use std::ifstream to read line by line, and boost::split to split the line by ,.

Sample code:

You could check tokens size for sanity checks of file loaded.

#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;
}

You could also use String Toolkit Library if you don't want to implemented. Docs

NetVipeC
  • 4,402
  • 1
  • 17
  • 19
  • That seems like it might work. My thinking was that a dedicated config reading library would be best, but is that not likely to be the case when my data is so simple? – lkrasner Jul 23 '14 at 19:13