Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/tutopal.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 438

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/tutopal.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/tutopal.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/tutopal.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/tutopal.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 438

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/tutopal.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/tutopal.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/tutopal.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 764

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/tutopal.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 438

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/tutopal.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/tutopal.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/tutopal.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/tutopal.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 438

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/tutopal.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/tutopal.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/tutopal.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 764

Warning: ftp_mkdir() expects parameter 1 to be resource, null given in /home/wvyrfnwn/tutopal.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 580

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/tutopal.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 438

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/tutopal.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/tutopal.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230
Resolve the Error “iso c++ forbids converting a string constant to ‘char*’” - TutoPal

Resolve the Error “iso c++ forbids converting a string constant to ‘char*’”

C++ is a general-purpose and high-level programming language used by programmers and developers to develop operating systems, browsers, various applications, data structures, and in-game programming. When you are working with C++, you may get the error “iso c++ forbids converting a string constant to ‘char*’”.

Errors always seem frustrating all the time they appear, the same goes with this one. There is no need to worry as you have chosen to come to Tutopal to fix the error, we leave no stone unturned to provide you with the best possible solutions to make you crack the code just the way you want. Let’s start with how the error arises

How the error shows up

When you are working on a C++ project, you end up with an error warning. This is what you get:

ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

The script you tried is:

char const *q = "pin";
char const *r = "\n\r";
{
while(client.findUntil(*q, *r)) 

The origin code you used:

while(client.findUntil("pin", "\n\r"))

You must be wondering what measures to take to get rid of the error. Check out the solutions to tackle it

Solutions To Handle the Error “iso c++ forbids converting a string constant to ‘char*’”

Solution 1 – Copy the string literals into editable arrays

To fix the error more simply and efficiently, you just need to copy the string literals into editable arrays. To do that, follow the code below

char q[] = "pin";
char r[] = "\n\r";
{
    while(client.findUntil(q, r)) 

Solution 2 – Use the findUntil correctly

This is another way to resolve the error. The error message you get shows that your program is not properly formed. No declaration is shown, but from context, it concludes the findUntil argument is char*.  No string literal can be passed to such a function. It is though well formed to pass a string literal as char*before C++ 11, it is deprecated.

As you have tried using this in your code

char const *q = "pin";
char const *r = "\n\r";

Although it is correct, the following makes no sense

while(client.findUntil(*q, *r)) 

First, you try to pass a string, and later indirectly through a character pointer, which shows passing a character. It is not going to work unless your function is a template. Even findUntil(q, r) can’t work as the conversion of pointers to const to a pointer to non-const will not work. The correct way is to make the string literal copy into arrays that can be edited. Like this:

char q[] = "pin";
char r[] = "\n\r";
{
    while(client.findUntil(q, r)) 

An alternative to solve the error is to make findUntil instead accept a pointer to const char. Later, use string literals because conversion to a pointer to const char is possible.

Conclusion

In this post, we highlighted the solutions to fix the error “iso c++ forbids converting a string constant to ‘char*’”. I hope you find it useful!

I wish you a happy error-solving!

Posted in C++

Leave a Reply

Your email address will not be published. Required fields are marked *