FILE* fopen(const char* kcpFilename, const char* kcpMode);
Mode String | Mode Description |
"a" | This opens the file for writing at the end of the file (appending) or it creates a new file if it does not already exist. |
"a+" | This opens the file for writing at the end of the file (appending) or it creates a new file if it does not already exist. It also opens the file for reading. |
"r" | This opens a file for reading only. The file must exist prior to opening. |
"r+" | This opens a file for read and writing. The file must exist prior to opening. |
"w" | This opens a file for writing only. If the file exists, it is erased when opened. |
"w+" | This opens a file for reading and writing. If the file exists, it is erased when opened. |
"b" | This opens a file in binary mode as opposed to the default ASCII text mode. |
"ccs" | This opens a file in UNICODE text mode. |
#include <cstdio> int main() { char* cpFileName = "XoaX.txt"; // Open an ASCII text file for reading FILE* qpFile = fopen(cpFileName, "r" ); // Check that the file was opened successfully. if (!qpFile) { printf("Could not open %s for reading \n", cpFileName); return 1; } char caBuffer[50]; // Read in the first and only line of text char* cpReturn = fgets(caBuffer, 50, qpFile); if (cpReturn) { printf("Read in: %s\n", caBuffer); } fclose(qpFile); return 0; }
© 20072024 XoaX.net LLC. All rights reserved.