|
-
August 11th, 2009, 11:55 AM
#1
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... takes too much time as the file size is bigger..
}
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 line then 1001 to 2000 lines... upto max line count...
reg,
Subbu
-
August 13th, 2009, 06:44 AM
#2
Re: Read 1000 Lines from text file in a single shot ........
Im having a similar problem.. I want to read the string on line 6 of my textfile without having to read the 5 lines before it. is this possible or do i have to pad each string to 20 spaces (char[20]) and then search for charecter position 101 -120 (equivilant to line 6)?
help would be appreciated!!
I am making a Member Record and Edit Program using files.
-
August 14th, 2009, 07:37 AM
#3
Re: Read 1000 Lines from text file in a single shot ........
Im having a similar problem.. I want to read the string on line 6 of my textfile without having to read the 5 lines before it. ... is this possible or do...
No it's not possible - a line is determined by a '\r' followed by a '\n' character (in Windows).
Therefore 5 lines can occupt 20 bytes or 200Mb depending on the line size and you have no way of knowing this without reading every character in the file looking for the above characters.
As to subbuchen's question the same thing applies. However you can read large chunks of data from the file using the ifstream's read method.
Darwen.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|