Read 1000 Lines from text file in a single shot ........
-
Hi, Below is the line of code(C++) for Reading the Textfile line by line. CString = strFilePath; // text path file path ifstream Textfile; Textfile.open(strFilePath,ios::in); std::string value; while(!Textfile.eof()) { getline(Textfile,value); // Read line by line... } Textfile.close(); Now the question is I am having 40MB text file size. I need to read 1000 Lines in a single shot (And upto read 1000 times to reach the whole 40 MB size) not line by line. How to do this? (ie from 1 to 1000 and 1001 to 2000.... reach max lines) reg, Subbu
-
Hi, Below is the line of code(C++) for Reading the Textfile line by line. CString = strFilePath; // text path file path ifstream Textfile; Textfile.open(strFilePath,ios::in); std::string value; while(!Textfile.eof()) { getline(Textfile,value); // Read line by line... } Textfile.close(); Now the question is I am having 40MB text file size. I need to read 1000 Lines in a single shot (And upto read 1000 times to reach the whole 40 MB size) not line by line. How to do this? (ie from 1 to 1000 and 1001 to 2000.... reach max lines) reg, Subbu
To read a line from a file, you effectively need to read the file character by character - that's how you find the line termninator character. Sounds to me like you'd be better off memory mapping the whole file and processing it in memory
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Hi, Below is the line of code(C++) for Reading the Textfile line by line. CString = strFilePath; // text path file path ifstream Textfile; Textfile.open(strFilePath,ios::in); std::string value; while(!Textfile.eof()) { getline(Textfile,value); // Read line by line... } Textfile.close(); Now the question is I am having 40MB text file size. I need to read 1000 Lines in a single shot (And upto read 1000 times to reach the whole 40 MB size) not line by line. How to do this? (ie from 1 to 1000 and 1001 to 2000.... reach max lines) reg, Subbu
spalanivel wrote:
How to do this?
You can't. You can, however, reduce file I/O by reading the entire file once into a buffer and then process that buffer instead. See Stuart's suggestion.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons