I have a problem with writing number to a file with ofstream. When i write numbers there are characters like this █ instead of numbers. The method i write to the file is:
byte _b = 20;
ofstream p_file;
p_file.open("txt.txt", std::ios::app);
p_file << _b;
Is there any way to be right, or just use another filewriter method? Thanks.
EDIT:
p_file << (int) _b;
works fine. Thanks
I bet that
byteischaror some variant thereof. In that case you are setting_bto the character with code 20, which in ASCII is a control character. The stream output will try to output the character not the number.You can cast it to another integral type if you want to obtain the number: