0

What is the fastest way to read a text file into a string variable? There can be many possible ways in which it can be done, but I am asking for the fastest.

In my case, I've a txt file which can contain upto million entries. This file would contain a word in each line, and I need to operate on each word.

atuljangra
  • 417
  • 1
  • 5
  • 9
  • If you want to operate on each word, then reading the whole file into one string seems like the wrong first step. Especially when you have so much data. – john Sep 29 '13 at 12:46
  • I don't want to go and read from the file again and again. I think that would be a huge overhead. Any suggestions? – atuljangra Sep 29 '13 at 12:57
  • How about reading it to a vector of strings? Unfortunately there are no answers to questions like 'which is the fastest way', because different methods work well in different situations. Really you're just going to have to try different things and see. If you really do need speed however I would avoid C++ I/O which is often quite slow. – john Sep 29 '13 at 13:14
  • Yes, I'm doing reading into a vector of strings.t – atuljangra Sep 29 '13 at 13:52

0 Answers0