0

C++ で OBDII 読み取りライブラリ/アプリケーションを作成しています。単純な文字列コマンドを送信し、各パラメータに固有の関数を介して結果を渡すことによって、自動車のコンピュータからデータを取得します。

必要なすべてのコマンドの構成ファイルを読みたいと思います。おそらく次のようなものです。

Name, Command, function

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

基本的には非常に単純で、すべてのデータを文字列として読み込むだけで済みます。これに適した単純なライブラリを推奨できる人はいますか? 私のターゲットは Linux の g++ および/または Clang です。

4

1 に答える 1

2

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を使用することもできます。ドキュメント

于 2014-07-23T19:07:26.223 に答える