Dieses minimale Beispiel zeigt, wie man tab-separierte Dateien (TSV) in C++ einlesen kann. Unser Beispiel nutzt boost::algorithm::split
, um jede Zeile in ihre tab-separierten Werte aufzuspalten.
#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)) { // Split line into tab-separated parts vector<string> parts; split(parts, line, boost::is_any_of("\t")); // TODO Your code goes here! cout << "First of " << parts.size() << " elements: " << parts[0] << endl; } fin.close(); }