Archived

This topic is now archived and is closed to further replies.

XDarkScar

fstream read and write

Recommended Posts

I know how to do that but how do you read from a certian area bla bla bla bla bla bla| bla bla| bla bla bla bla how would you read from the area with the | second question how would you write to a certain area? tx for your replys Easy way of programming: Code, Graphics, Swearing....

Share this post


Link to post
Share on other sites
Are you trying to read from a specific area in a file? If so you can use delimeters. These act as referece points to a file for example you could read in a file and only copy the file into a buffer after reaching one. They can be anything you like, but single character delimeters are easier to check. I like to use the tilde character.

Share this post


Link to post
Share on other sites
You could write to the file as binary, and then read the file as binary of course and to specify a point in the file you could use an offset from the beginning of the file.

Share this post


Link to post
Share on other sites
i'm not sure exactly what you want to do...

getline(infile, temp, '|');  


will read everything until it hits a |. you could also use ignore if you don't need the data before the |. then you could process data after the | if that's what you need. if you need the data on the line with the |, then something like this might work (haven't tried this code):


string line;
getline(infile, line, '\n');
while(infile)
{
if(line[line.length()-1] == '|')
{
//do something with this line
}
getline(infile, line, '\n');
}

that should read line by line and check the very last character of the string it read to see if it is a |. if it is, then you do something with the line you just read in the if block.

[edited by - bjl3784 on May 4, 2003 10:27:42 AM]

Share this post


Link to post
Share on other sites