Use the fopen () function to read and write files in Visual C ++

zhaozj2021-02-08  281

Using the fopen () function in Visual C to read and write Liu Zhirong Many friends who have used Turbo C like to use the fund () function to read and write files, you can also use fopen () to read and write files in the Visual C environment. And you can use the standard Open File dialog box in Visual C , which makes it easier to select the path to the read / write file. Specific practice is this. First you need to use the MFC basic class library, plus a new class derived by the CFiledialog class in your original Visual C program, for example CMYFILEDIALOG, then define an object with this new class, for example: MyDLG, use this Object's Domodal () method, you can call out the dialog box. In this way, you can open the read-written file when you pass the selected path name and file name to the FOPEN () function. CMYFILEDIALOG MyDLG (TRUE); Define a dialog object mydlg.domodal (); exhaled open file dialog CString filename; define a string of a cString type to store the path of the file and file name FileName = mydlg.getPathname (); get file The path and file name Since the filename parameter required in the fopen () function is a character type, we also need to convert the file name of the CString type into a variable of the character type. INT I, Length; Define I as a loop variable, define the length of the length of the file path and file name; define the Char type character pointer to store the file name, use length = filename.getlength () (). Assign the length of the file name to the length = new char [length]; assigns memory space for the CHAR type pointer variable FileName, I = 0; I

转载请注明原文地址:https://www.9cbs.com/read-1533.html

New Post(0)