Using only standard library tools:
#include <sstream> #include <fstream> #include <string> #include <vector> std::ifstream file("file.txt"); std::string line; std::string partial; std::vector<std::string> tokens; while(std::getline(file, line)) { // '\n' is the default delimiter std::istringstream iss(line); std::string token; while(std::getline(iss, token, '\t')) // but we can specify a different one tokens.push_back(token); }
Here you can get some more ideas: How do I want tokenize a string in C ++?
source share