Working with text file
1. namespace
The namespace System::IO is used to work with file reading and writing
2. Save text string into a file
1). Create a StreamWriter
StreamWriter^ outfile = gcnew StreamWriter(“TextFilePathAndName.txt”);
2). Write text to “TextFilePathAndName.txt”
outfile->Write(“Text to write”);
For other write method please refer to StreamWriter
3). Close the StreamWriter
outfile->Close();
For save binary data into a file, please refer to here.
3. Read text from a file
1). Check the file exists
File::Exists(“TextFilePathAndName.txt”);
2). If the file exists, open the file
StreamReader^ sr = gcnew StreamReader((“TextFilePathAndName.txt”);
3). Read text from the file
a). Read a line
String^ line = sr->ReadLine();
b). For other read method please refer to StreamReader methods
4). Close the file
sr->Close();
For read a birnary data from file, please refer to here.
Pingback: Working with binary file | Code References
283651 886959Hi there, just became alert to your blog via Google, and discovered that it