CStdioFile file; file.Open("test.txt", CFile::modeWrite | CFile::modeCreate); file.WriteString("Hello world!"); file.Close();
CStdioFile file; file.Open("test.txt", CFile::modeWrite | CFile::modeCreate); file.WriteString("Line 1\n"); file.WriteString("Line 2\n"); file.WriteString("Line 3\n"); file.Close();In this example, three lines of text are written to the file "test.txt" using three calls to WriteString(). The "\n" character is used to represent a new line. Overall, CStdioFile's WriteString() method is an effective way to write text to a file in C++ using MFC package library.