product->scheme->edit scheme
run->options->use custom working directory: small folder selection
string filename;
cin>>filename;//文件名
FILE *fpin;
if((fpin=fopen(filename,"r"))!=NULL)//只读
{
break;
}
else
cout<<"文件输入错误!请输入源文件名:";
FILE *fpin;
fpin=fopen("xx.txt","r");//Read only
Define the function
FILE * fopen(const char * path, const char * mode);
function description The
parameter path string contains the file path and file name to be opened, and the parameter mode string represents the stream form.
Mode has the following types of strings:
r Open a read-only file, the file must exist.
r+ Open a readable and writable file, the file must exist.
w Open the write-only file. If the file exists, the file length is cleared to 0, that is, the content of the file will disappear. If the file does not exist, create the file.
w+ Open a readable and writable file. If the file exists, the file length is cleared to zero, that is, the content of the file will disappear. If the file does not exist, create the file.
a Open the write-only file in append mode. If the file does not exist, it will be created. If the file exists, the written data will be added to the end of the file, that is, the original content of the file will be retained.
a+ Open readable and writable files in append mode. If the file does not exist, it will be created. If the file exists, the written data will be added to the end of the file, that is, the original content of the file will be retained.
All of the above-mentioned morphological strings can be added with a b character, such as rb, w+b or ab+. The b character is added to tell the library to open the file as a binary file instead of a plain text file. However, in POSIX systems, including Linux will ignore this character. The new file created by fopen() will have S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH(0666) permissions, and the file permissions will also refer to the umask value.
Return value After the
file is successfully opened, the file pointer to the stream will be returned. If the file fails to open, NULL is returned and the error code is stored in errno.
Or put the txt file in the debug folder and use the freopen() function to open