I'm working on a challenge to build a C++ text adventure game that will fit on a 1.44MB floppy disk. I'm using ASCII art for chapter images. Each ASCII art image is made out of 40 "cout" lines with 78 character in the line to form the image.
For example:
cout << "#############################################################################" << endl;
From my understanding, "cout" defines the contents as a "const char".
After some research I understand a char data type is 1 byte but I could not find a reliable answer to the size of a "const char".
If I'm understanding the data size right, the maths for one ASCII image should be 78(char)*40(lines) to get 3120 bytes or 3.12KB.
I'm unsure whether or not the characters themselves effects the size and if the addition of "const" increase the data size.
It does not.
std::coutis anstd::ostreamfor which there are a number ofoperator<<overloads of which one is:This merely reads the characters pointed at by
suntil a null terminator (\0) is encountered and outputs them to the device.constness doesn't affect the size. The size of aconst charis the same as the size of a non-constchar- and the size is defined to be 1. You can print the result ofsizeof(char)andsizeof(const char)to verify.78*40 equals 3120, that's correct, but 3120 bytes is not 3.12 KB.
KBis the old way of writingKiB, that is, kilobinary. 3120 is 3.046875 KiB or 3.12 kB.