I want to load separately the words on a text file like
text.txt
Hi this is a text file
with many words
I don't know how many
into a vector<string>
how do I go about it?
I want to load separately the words on a text file like
text.txt
Hi this is a text file
with many words
I don't know how many
into a vector<string>
how do I go about it?
I'll give you the general algorithm rather than the code.
What about this:
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char* argv[]) {
vector<string> strings;
string word;
ifstream input(argv[1]);
while(!input.eof()) {
input >> word;
strings.push_back(word);
}
return 0;
}
It depends what kind of delimiter you'd be using really.