ReadLine & Write

ramCC

Member
Joined
Jun 7, 2004
Messages
9
Hi all,

I want to open a status file for both reading and writing. (Managed C++ or C#)
I need to read a line, and than according to some logic change 1 char in the middle of it. (status)

I know that I can use FileStream for read and write. but FileStream does not give me the option to read a whole line...

I can go the hard way and read char by char until I get to a newline sign, for reading 1 full line from the file. But Im sure that there is some way for me to be able to read a whole line , and do some manipulations on it.

I also need to be able to scan the file with a file pointer so I will be able to change this 1 char I was talking about.

Thanks for any help!
 
Sequential access means you can either read or write... you cant read, look at it, and then write it just by reading lines.
To do what you are talking about, you need to read in the whole file (into a string, perhaps, or maybe an array of strings that hold each line), find the line that you want to modify, modify it, and then write everything you have back to the file.
You can use the StreamReader to read a line. Similarly, the StreamWriter will write a line.
Not sure what you mean by scan the file with a file pointer. You can pass a reference to a StreamReader or a FileStream, and read from that. :)
 
Back
Top