tRoNiX Posted October 25, 2003 Posted October 25, 2003 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 Quote
*Experts* mutant Posted October 25, 2003 *Experts* Posted October 25, 2003 You can read a file using the IO::StreamReader object. Here is an example: //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: '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(); Quote
tRoNiX Posted October 25, 2003 Author Posted October 25, 2003 But i want scan a determinated line and use it with a variable, like the fscanf of PHP Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.