Casting doesnt work ... [SOLVED] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Casting doesnt work ... [SOLVED]

Hi there ... why isnt that code printing any numbers ...? The array holds the right numeric values - but they wont appear on stdout :( #include <iostream> using namespace std; int main () { char array[7] = {'*','*','*','*','*','*','*'}; int i,j; for(i= 0; i < 7; i++) { array[i] = static_cast<char>(i +1); for(j = 0; j < 7 ;j++) { cout << array[j]; } cout << endl; } return 0; }

1st Aug 2020, 5:54 PM
Oliver
1 Answer
0
And what about doing the casting in a seperate line? like: char temp; temp = (char)(i+1); cout << temp; ? If i debug the code, i can see that the array holds '1','2', ... ?!
1st Aug 2020, 6:06 PM
Oliver