Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.(5)

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/ Questions/Resolved the problem of the iso c++ forbids converting a string constant to ‘char*’
Next
Answered
Emmet Rodriguez
  • 10
Emmet Rodriguez
Asked: May 18, 20222022-05-18T07:02:02+00:00 2022-05-18T07:02:02+00:00In: cpp

Resolved the problem of the iso c++ forbids converting a string constant to ‘char*’

  • 10

. Advertisement .

..3..

. Advertisement .

..4..

I am working on cpp, but I found the following warning message:

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

Is there any way to stabilize the issue “iso c++ forbids converting a string constant to ‘char*’”?
I read a lot of topics about this, but all of them were trying to install anything. Is this the correct way, or any recommendation for me?
Please find the beginning command below:

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

converting a string constant to ‘char*’
  • 2 2 Answers
  • 649 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

2 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    hdtutoria Expert
    2022-06-10T04:03:09+00:00Added an answer on June 10, 2022 at 4:03 am

    The cause: The warning shown that your program is ill-formed. You didn’t provide the declaration, but we can assume from the context that the findUntil argument is char*. A string literal cannot be passed to such a function.

    The solution: You can fix this error by copying string literals into editable arrays:

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

    Another option is to fix findUntil to accept a pointer to const char instead. Then, because string literals can be transformed to a pointer to const char, you can utilize them.

    • 6
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Adam Guillon
    2022-05-25T20:11:09+00:00Added an answer on May 25, 2022 at 8:11 pm

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

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

    This warning indicates that your program is not well-formed. Although you didn’t display the declaration, context can help us to determine that findUntil‘s argument is char*. A string literal may not be passed to such a function.

    It was once well-formed, but now deprecated. To pass a string literal such as char* before C++11, it used to work.

    I tried:

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

    These statements are true by themselves.

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

    This is absurd. You were trying to pass a string previously, but you now indirect through the character pointeder so that you are passing a character. This cannot work unless the function is a template.

    findUntil(q, r) will not work, either because pointers to const won’t implicitly transform to non-const.

    The best solution is to convert string literals into modifiable ranges.

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

    Another option is to change findUntil so that it accepts a pointer-to const char instead. String literals can then be used, as they can be converted into a pointer-to const char.

    • 18
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.