is following syntax right??? if yes then why my compiler is giving error
also if this is not right then please tell me, What you think my teacher wanted to tell me by this code he said run this and in file you will see characters not numbers from 0 to 255
1 2 3 4 5
for(int i = 0; i < 256; i++){
filehandle.write(&i, sizeof(i));
}//-------for
yes it did work but this time it's putting 3 space characters after each character. Is it due to the sizeof(i) I used
and reinterpret_cast<char*>(&i) it converts integer to characters constant pointer right???
Yes. sizeof(int) and sizeof(char) are usually different. It wouldn't be space characters, but characters with ascii value 0 (which your editor may show as spaces.)
In this case, the reinterpret_cast converts from pointer to int to pointer to char which just means we're going to interpret the bits that make up whatever is pointed to (i in this case) as the type referenced by the pointer type we converted to. (In other words, we interpret the bits of i as if it was an array of char.)
worked but not well, yes there was something on console this time but it were a few weird symbols those could be ASCII representations of first few 10,12 characters but after about 10 characters it is all down-arrow symbols
then I used (int)c {by the way atoi didn't work as it needed const char, and my c was a variable char} and result was 0-25 and afterward just 25 repeatedly and nothing else till loop reached EOF(I guess)