View Single Post
Join Date: Nov 2007
Posts: 390
Reputation: skatamatic will become famous soon enough skatamatic will become famous soon enough 
Solved Threads: 39
skatamatic skatamatic is offline Offline
Posting Whiz

Re: searching for keywords in multiple text files

 
0
  #8
Jan 10th, 2009
Originally Posted by serhannn View Post
Thanks for the explanation, but I still don't understand how I can load text files, which I need to search, into a string vector. Should I get them line by line and load into a vector using "getline" or is there another thing to do?
You can load the files in using the fstream.

  1. ifstream inFile;
  2. vector<string> data;
  3. inFile.open("File.txt");
  4. while (!inFile.eof())
  5. {
  6. string sString = inFile.getline();
  7. data.push_back(sString);
  8. }

Something like that should do the trick for filling a vector from a file. It might not be syntactically correct, since I didn't try to compile it.
Reply With Quote