求助
c++吧
全部回复
仅看楼主
level 1
下面的代码中为什么去除注释,加入读文件的一段,前面的写入不成功了?什么原因。
#include<stdio.h>
#include<stdlib.h>
#include <conio.h>
#include<iostream>
#include <string.h>
#include<fstream>
using namespace std;
void zhuan(int shu[]);
int b[10], q[10]={
9, 8, 7, 6, 5, 4, 3, 2, 1};
int main() {
FILE *fp1 = fopen("1.txt", "wb");
zhuan(q);
fwrite(&b, sizeof(b), 1, fp1);
/*if ((fp1 = fopen("1.txt", "rb")) == NULL) {
fprintf(stderr, "Cannot open output file.\n");
return 1;
}
ifstream fin("1.txt");
int Num[50];
for (int j = 0; j < 5; j++) {
fin >> Num[j];
cout << Num[j] << endl;
}*/
fclose(fp1);
getch();
return 0;
}
void zhuan(int shu[]) {
int a[50];
for (int i = 0; i < 50; i++) {
a[i] = shu[i];
if (a[i] != ' ')
b[i] = a[i] + '0';
else
b[i] = a[i];
}
}
2015年05月23日 13点05分 1
level 1
求助!
2015年05月24日 14点05分 2
level 3
shu[]只有10个,却要循环50次,,,
2015年05月24日 14点05分 3
谢谢!原来的q[]是定义为q[50]的。现在改为循环次数小于10,问题同样存在。继续求助。
2015年05月25日 15点05分
1