fstream read and write
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....
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.
can you post an example, im sort of a noob to C++, finishing up a text game, and I need that info 2 learn from
Easy way of programming: Code, Graphics, Swearing....
Easy way of programming: Code, Graphics, Swearing....
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.
i'm not sure exactly what you want to do...
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):
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]
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement