The code is as follows.
// EOF example.cpp: Define the entry point of the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
int main()
{
char ch;
FILE *f;
char a[300];
printf("enter the file name:");
scanf("%s", a);
f = fopen(a,"r");
if (f == NULL)
{
printf("failed to open file. ");
exit(1);
}
while (( ch=getc(f)) != EOF)
{
putchar(ch);
}
fclose(f);
getchar();
return 0;
}
Solution: project property page (ALT + F7) – > Configuration properties – > C++ -> Code generation – > Basic runtime check defaults
But it can’t solve the problem, so I set the input. TXT file format to ANSI instead of UTF-8 or Unicode, which is correct
In addition, when using scanf and fopen functions, the solution is as follows
Right click the project name – > Attributes – > C/C++–> Preprocessor – > To define the preprocessor, edit the input box on the right and add:
to it_ CRT_ SECURE_ NO_ WARNINGS
Similar Posts:
- C++ Error: Run-Time Check Failure #2 – Stack around the variable ‘cc’ was corrupted.
- C write and read file via FILE and open method in a+ or r mode
- How to solve Visual Studio error C4996
- [Solved] VS error C4996: ‘scanf’: This function or variable may be unsafe.
- Solve the security check error similar to error c4996: ‘scanf’: this function or variable may be unsafe in vs2019
- [Solved] Undefined reference_G++ _GLIBCXX_USE_CXX11_ ABI compilation error: STD:: Basic_String and STD::__cxx11::basic_String cannot match
- format not a string literal and no format arguments
- How to Solve Const variable assignment Error
- The solution of “no matching function for call to…” in G + + compilation
- error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup