By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,641 Members | 2,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,641 IT Pros & Developers. It's quick & easy.

Read large data files

P: 2
Hi everybody,
Please can you tell me how can I read large data file (> 15 millions line) in C/C++ languge.

Thanks for your help,
Claire
Aug 13 '07 #1
Share this Question
Share on Google+
3 Replies


Meetee
Expert Mod 100+
P: 931
Hi everybody,
Please can you tell me how can I read large data file (> 15 millions line) in C/C++ languge.

Thanks for your help,
Claire
You can use vectors for this:

1. declare/open a file-stream for reading (using std::ifstream )
2. declare a vector of strings (std::vector<std::string>)
3. if you haven't already reached the end of file, then do the following, else goto 8:
4. declare a temporary string that will hold the next line (std::string temp;).
5. fill this temporary string with the current line of your file (std::getline)
6. add the string to your string-vector (using push_back function)
7. go back to 3
8. close the file

If you are not aware of vectors then http://www.cppreference.com/cppvector/index.html

Regrads
Aug 13 '07 #2

gpraghuram
Expert 100+
P: 1,275
Gi,
If the file size is huge then reading it at a short wont be very effective.
Try to split the file into smaller sizes and then have a logic to to open these files in a loop on by one and then read it

Raghuram
Aug 13 '07 #3

P: 2
Thanks a lot.
best,[

QUOTE=zodilla58]You can use vectors for this:

1. declare/open a file-stream for reading (using std::ifstream )
2. declare a vector of strings (std::vector<std::string>)
3. if you haven't already reached the end of file, then do the following, else goto 8:
4. declare a temporary string that will hold the next line (std::string temp;).
5. fill this temporary string with the current line of your file (std::getline)
6. add the string to your string-vector (using push_back function)
7. go back to 3
8. close the file

If you are not aware of vectors then http://www.cppreference.com/cppvector/index.html

Regrads[/quote]
Aug 14 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.