int :: cadena calculatelenght(const cadena& a, const char* cad)
{
cadena c;
int lenght = 0;
char* punt; punt = cad;
while(*punt){
lenght++; punt++;
}
return lenght;
}
I have this problem, I want to calculate the length of a C string without using functions like strlen
, in other methods of my cadena class I can because is not const char*, but now I don't know what to do.
In C++, the error invalid conversion from 'const char*' to 'char*' happens when you try to pass a nonmodifiable constant char for char. C++ throws this error to let you know you are performing an operation that is not possible.
const char* is a mutable pointer to an immutable character/string. You cannot change the contents of the location(s) this pointer points to. Also, compilers are required to give error messages when you try to do so. For the same reason, conversion from const char * to char* is deprecated.
You can declare punt
to be of the correct type:
const char * punt = cad;
You need:
const char* punt; punt = cad;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With