这是我的程序的开始,它生成 10 的长字符串。每次我尝试将 bigfor 设置为“0”时,它都会说它需要从常量 char 转换为 char。这是怎么做到的?
// basic file operations
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
int main () {
char bigfor[10];
int arrayvar = 0;
int a;
int b;
int c;
int d;
int e;
int f;
int g;
int h;
int i;
int j;
// Constants
int variable1 = 0;
int variable2 = 1;
int variable3 = 2;
int variable4 = 3;
int variable5 = 4;
int variable6 = 5;
int variable7 = 6;
int variable8 = 7;
int variable9 = 8;
int variable10 = 9;
for (a=0; a < 36; a++)
{
switch (a)
{
case 0:
bigfor[variable1] = "0";
break;
case 1:
bigfor[variable1] = "1";
break;
case 2:
bigfor[variable1] = "2";
break;
case 3:
bigfor[variable1] = "3";
break;
case 4:
bigfor[variable1] = "4";
break;
case 5:
bigfor[variable1] = "5";
break;
case 6:
bigfor[variable1] = "6";
break;
case 7:
bigfor[variable1] = "7";
break;
case 8:
bigfor[variable1] = "8";
break;
case 9:
bigfor[variable1] = "9";
break;
}
ofstream myfile;
myfile.open ("codes.txt");
myfile << bigfor[variable1];
myfile << bigfor[variable2];
myfile << bigfor[variable3];
myfile << bigfor[variable4];
myfile << bigfor[variable5];
myfile << bigfor[variable6];
myfile << bigfor[variable7];
myfile << bigfor[variable8];
myfile << bigfor[variable9];
myfile << bigfor[variable10];
myfile << '\n';
myfile.close();
}
return 0;
}