I have this block of code:
int myFunc( std::string &value )
{
char buffer[fileSize];
....
buffer[bytesRead] = NULL;
value = buffer;
return 0;
}
The line - buffer[bytes] = NULL is giving me a warning: converting to non-pointer type 'char' from NULL. How do I get rid of this warning?
Don't use NULL
? It's generally reserved for pointers, and you don't have a pointer, only a simple char
. Just use \0
(null-terminator) or a simple 0
.
buffer[bytesRead] = 0;
// NULL is meant for pointers
As a suggestion, if you want to avoid copying and all then, below can be considered.
int myFunc (std::string &value)
{
s.resize(fileSize);
char *buffer = const_cast<char*>(s.c_str());
//...
value[bytesRead] = 0;
return 0;
}
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