TSV (tabulatorgetrennte Werte) in C++ lesen
English
Deutsch
Dieses minimale Beispiel zeigt Ihnen, wie Sie eine tabulatorgetrennte Werte-Datei (TSV) in C++ lesen und parsen. Wir verwenden boost::algorithm::split, um jede Zeile in ihre tabulatorgetrennten Komponenten aufzuteilen.
read_tsv.cpp
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <boost/algorithm/string.hpp>
using namespace std;
using namespace boost::algorithm;
int main(int argc, char** argv) {
ifstream fin("test.tsv");
string line;
while (getline(fin, line)) {
// Zeile in tabulatorgetrennte Teile aufteilen
vector<string> parts;
split(parts, line, boost::is_any_of("\t"));
// TODO Ihr Code kommt hier rein!
cout << "Erstes von " << parts.size() << " Elementen: " << parts[0] << endl;
}
fin.close();
}Check out similar posts by category:
C/C++
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow