There are many similar queries, but in my case, I donโt understand what is not working:
int mysize = 0;
mysize = sizeof(samplestring) / sizeof(*samplestring);
std::cout << mysize << '\n' << samplestring;
It is output:
4
Press 'q' to quit.
How is this possible? 4 is definitely not the size of this line. I even tried the following, with the same result:
mysize = sizeof(samplestring) / sizeof(samplestring[0]);
EDIT: Ok, this announcement:
char *samplestring = "Start.";
I am in C ++, but I need to use functions that accept only char *. Later in the code, I assign new lines to this variable, for example:
samplestring = "Press 'r' for red text.";
Yes, the compiler gives me warnings, but I have no idea how I can use different lines if I can not overwrite them ...
source
share