标签:its char fputc fopen strlen bsp include pac The
中国大学MOOC上北大的题目做完后需要提交通过码,可以通过 右键->打开方式->记事本 打开,不过有时候通过码数量比较多,一个个打开比较麻烦,可以用标准C的文件读写,结合一些C++特性来节省时间
1 #include <bits/stdc++.h> 2 #include <algorithm> 3 using namespace std; 4 FILE *fp,*fout; 5 int main () { 6 cout << "Input the length of the digits:"; 7 int len; 8 cin >> len; 9 10 cout << "Input the num of fils:"; 11 int n; 12 cin >> n; 13 14 fout=fopen("result.txt","w"); 15 16 string head="acckey",dig,re; 17 char s[10]; 18 19 for (int i=1;i <= n;++i) { 20 itoa(i,s,10); 21 dig.append(len-strlen(s),‘0‘); 22 dig.append(s); 23 re=head+dig; 24 dig.clear(); 25 26 cout << "Reading " << re << endl; 27 fp=fopen(re.c_str(),"r"); 28 char c; 29 fputc(‘\n‘,fout); 30 while (fscanf(fp,"%c",&c) != EOF) { 31 fputc(c,fout); 32 } 33 fclose(fp); 34 } 35 36 fclose(fout); 37 cout << "Finished"; 38 }
标签:its char fputc fopen strlen bsp include pac The
原文地址:https://www.cnblogs.com/Nikola-K/p/12234516.html