Reading text

tRoNiX

New member
Joined
Oct 25, 2003
Messages
2
Location
Chile
I want to do that:

read this line of a text file:

users = 20

and how can i modify the 20?

in visual c++.net
 
You can read a file using the IO::StreamReader object. Here is an example:
C#:
//create a new StreamReader object and pass in the path to the file
System::IO::StreamReader* r = new System::IO::StreamReader("path to the file");
//create a string variable to hold the value that you read from the file
//in this example you are only reading one line because ReadLine() method is used
String* fcontent = r->ReadLine();
//close the stream
r->Close();
This how you can read it, how you get out the info from the file is what you have to think of, it depends on how you format your file, where you put what and things like that.
If you want to write to a file use IO.StreamWriter class. Here is an example:
C#:
create a new StreamWriter object and pass in the path to the file to it
System::IO::StreamWriter* w = new System::IO::StreamWriter("path to the file");
//now you can write to the file using WriteLine or Write method
 w->WriteLine("This is a text");
//then you have to flush the sream to make sure everything is in the file now
w->Flush();
//and close it
w->Close();
 

Similar threads

L
Replies
0
Views
6
Lisa Schmeiser, No Jitter
L
U
Replies
0
Views
53
Umair Aslam Bhatti
U
N
Replies
0
Views
11
Nathan Eddy, No Jitter
N
Back
Top