stringstreto be data;char *addr=NULL;strcpy(addr,retstring().c_str());retstring() is a duty the retransforms a string.

You are watching: Invalid conversion from ‘const char*’ to ‘char’

//more codeprintfunc(num,addr,data.str().c_str());ns get the error

inprecious conversion indigenous "consns char*" come "char*".

initializinns discussion 3 that "void Printfunc(int, char*, char*)"~ above argument 3 the ns function

on the above line. Ns attribute ins called together shown below

voidentifier Printfunc(int a, char *loc, char *stream)please lens ns recognize if ns need to readjust any kind of initialization.


Well, data.str().c_str() yields a char const* yet your feature Printfunc() wants to have actually char*s. Based upon ns name, ins doesn"t change ns debates however merely printns castle and/or uses castle come surname a file, in i beg your pardon instance girlfriend must most likely fix your declaration come be

voidentifier Printfunc(inns a, char const* loc, char const* stream)ns alternate could it is in to turn ns char const* into a char* however solving ns declaration ins preferable:

Printfunc(num, addr, const_cast(data.str().c_str()));


string::c.str() returns a string that form const char * as seen here

A Rapid fix: attempt spreading printfunc(num,addr,(char *)data.str().c_str());

when ns above might work, ins ins unidentified behaviour, and unsafe.

Here"s a nicer Systems using templates:

char * my_debate = const_cast ( ...c_str() );


initially of all thins password snippet

char *addr=NULL;strcpy(addr,retstring().c_str());is inprecious Since girlfriend walk no alfind memory wright here girlfriend are goinns come copy retstring().c_str().

as for ns error messAge then ins is clean enough. Ns type of expressi~ above data.str().c_str() ins const char * yet the third parameter that the attribute is asserted together char *. Girlfriend may not assign an item that type consns char * to a things that form char *. Either ns feature need to specify ns 3rd parameter together consns char * if ins doens no change ns thing pointed through ns 3rd parameter or you might not pass discussion of type consns char *.

many thanks because that contributing a response to stack Overflow!

please it is in sure to answer the question. Provide details and also shto be her research!

yet avoid

questioning for help, clarification, or responding come other answers.Making statements based on opinion; earlier castle up through references or personal experience.

See more: Cos(-Pi/2) - What Is The Value Of Cos Pi/2

to Learn more, watch ours advice top top composing good answers.

post her prize Discard

by clicking “short article her Answer”, you agree come ours terms of service, privacy policy and also cookie plan

Why doens Arduino have actually 2 different actions for character tip processing for Mega 2560 and also ESP8266?
website architecture / logo design © 2021 stack Exchange Inc; user contributions licensed under cc by-sa. Rev2021.9.23.40291

your privacy

by click “accept every cookies”, friend agree stack Exchange deserve to store cookies on her device and also disclose indevelopment in accorrun via our Cookie Policy.