Write files to any directory in c++

高洛峰
Release: 2016-11-23 15:08:46
Original
1414 people have browsed it

Today I encountered an error when writing a file in a subdirectory of the C drive. I solved it after my own experiment. Make a small note.

The code is as follows:

#include
#include
#include

main()
{
int data[35];
int n=35, temp;
for(int i=0;i {
data[i]=i;
}
srand((unsigned)time(NULL));
FILE *fp;
fp=fopen( "C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\2016.11.22\random\Data Storage.txt","w");
for(int j=0;j {
temp=rand()%n;
printf("%4d",data[temp]);
fprintf(fp,"%4d",data[temp]);
if(temp+1!=n)
{
data[temp]=data[n-1];
}
n--;
}
fclose(fp);
}

At the beginning, just put the address of the file C:Program Files (x86)Microsoft Visual StudioMyProjects2016.11.22random copy to fprintf(), but an error will be reported when running. Finally, add one in front of each file to write the data.

Write files to any directory in c++

Write files to any directory in c++

Related labels:
c++
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!