• Register
1 vote


Hello Kodlogs,

I am going through a problem for the last few minutes. I tried to solve it in many ways but still couldn’t get rid of this. I’ve learning c++ programming language from last week. So, you can treat me as a novice in it.

I have a c++ program and I am trying to pass arguments through a function in it but it throws an error  c++ invalid conversion from const char* to char while I hit the run button.

Find my code snippet below and provide me a legit solution.

stringstream data;
char *addr=NULL;

And the function I tried to call:

void Printfunc(int a, char *loc, char *stream)

Thanks. Good day!

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

1 vote


As I can understand, retstring() is a function that returns a string. Before further proceeding check this.

However, your data.str().c_str() function produces a char const* but the function Printfunc()  wants char*s so, here comes the problem. In that case, you need to fix the declaration to solve the error.

Something like this:

void Printfunc(int a, char const* loc, char const* stream)

This should run fine, now. Give it a try and leave your feedback here.
Good day!

13 9 6
94,240 points

Related questions

0 votes
1 answer 18 views
Problem: I get the error invalid conversion from 'const char*' to 'char*'. initializing argument 3 of 'void Printfunc(int, char*, char*)'on argument 3 of the function on the above line. The function is called as shown below void Printfunc(int a, char *loc, char *stream) please let me know if I need to change any initialization.
asked Dec 27, 2020 Mashhoodch 9.6k points
0 votes
1 answer 5 views
0 votes
1 answer 10 views
Problem: Hello! I am a noob. I came to know about optional parameters in C++. My concept of optional parameters is not clear. Moreover, I read somewhere that in a function definition, an optional parameter must be placed first in the argument list. Is this true? Can anybody explain the concept of default arguments to me? Thank you.
asked Dec 4, 2020 Code Learner 6k points
0 votes
1 answer 7 views
Problem: What is a const member function in C++? What is the syntax of a const member function? How do you declare a constant in C++? What does const after a function mean?How member function can be called on a const object (or via a reference-or-pointer-to-const), and that the member function cannot modify data members (unless they're marked mutable ?
asked Dec 23, 2020 Mashhoodch 9.6k points
0 votes
2 answers 488 views
Problem : Below is the wrong form: int &z = 12; Following is the correct form: int y; int &r = y; Question: Why is a first code wrong? What is a "meaning" of a below error? “Invalid initialization of non-const reference of type from an rvalue of type”
asked Jan 24, 2020 jwilliam 3.9k points
1 vote
1 answer 230 views
Problem: I am getting an error from my very simple c++ program. It says invalid conversion from int to int* What does it actually mean? Why I am experiencing this error? I am attaching my code snippet below. Please, check the code and fix the error if you can. ... } and the output I am getting is: invalid conversion from `int*' to `int' Many thanks for your effort and valuable time, guys.
asked Apr 8, 2020 Gavin 15.3k points
1 vote
1 answer 463 views
Problem: Hello Kodlogs, I find you guys very helpful and friendly alongside. You people are helping each other proactively. It&rsquo;s nice to see. I have a simple piece of code written in C++ that is producing an error passing as this argument discards qualifiers. I can smell something very ... < itr->getId() << " " << itr->getName() << endl; } return 0; } I must recognize your concern. Thanks.
asked Apr 16, 2020 Gavin 15.3k points
0 votes
1 answer 22 views
1 vote
1 answer 99 views
Problem: Hello Experts, Well, I am looking for a simple solution. My problem might be silly to you guys but this thing driving me crazy so far. I&rsquo;ve bought an online course to learn C++ programming out of curiosity. Till this day I was doing good. I&rsquo; ... program that calls a function from another file. I mean, what is this? Could you please help out? I must recognize your help. Thanks.
asked May 3, 2020 Gavin 15.3k points