C 语言中打开文件的代码
FILE* inputFile;
const char * file_in;
if ((inputFile = fopen(file_in, "r")) == NULL) //读取输入文件{printf("\nerror: 无法打开输入文件: %s\n\n", file_in);std::cerr << "Parser: could not open input file '" << file_in << "'!\n";return EXIT_FAILURE;}
但若在 Visual Studio 下, 会提示 fopen 不安全, 建议使用 fopen_s.
//Declaring a variable of type errno_t to store the return value of fopen_serrno_t error_code1;//Opening file in r modeerror_code1 = fopen_s(&inputFile, file_in, "r");if (error_code1 != 0) {printf("Error! Failed to open file %s in r mode!", file_in);}