Converting a Constant Char to a char C++ -


here beginning of program makes long strings of 10. every time try set bigfor "0" says needs converted constant char char. how done?

// 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;       (a=0; < 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; } 

bigfor array of type char, you're putting strings it.

text between double quotes, such "0" interpreted compiler literal strings.

text between single quotes such '0' interpreted compiler literal chars.

so when add chars bigfor, should use single quotes tell compiler chars, instead of strings.

bigfor[variable1] = '0'; 

Comments