cannot convert 'StringSumHelper' to 'const char*' in initialization ERROR

I have this snippet of a script:

String User = "Logan";
char const* StepOne[50] = {User + "'s Device"}.c_str();
Tft.drawString(StringOne, 0, 0, 1, BLACK);

and its giving me this error: cannot convert ‘StringSumHelper’ to ‘const char*’ in initialization

Basically I want to combine strings and then output them to my screen. Help?

Sorry if this is kinda newbish and dumb, I’m very new to C/C++, I’m also a young adult person if that effects anything.

I’m not a big fan of the String class, but this works:

  String User = "Logan";
  String StepOne = User + "'s Device";
  Serial.println (StepOne.c_str ());

This is the code now:
String StepOne = User + "'s Device";
Tft.drawString(StepOne.c_str (), 0, 0, 1, BLACK);

And this is the error I'm getting now: error: invalid conversion from 'const char*' to 'char*'
(for Tft.drawString(StepOne.c_str (), 0, 0, 1, BLACK):wink:

What the hell is this?

{User + "'s Device"}

It certainly isn't a String.

invalid conversion from 'const char*' to 'char*'

So? Use a cast to lie to the function. Tell it that you are too lazy to learn to use strings (lower case s), so you need it to pretend that you are passing it a char *, when in reality you are passing it a const char *. Though why the f**k the function expects the input to be anything other than const is beyond me.

He's just a beginner, Paul, he said so himself. And it isn't his fault the function is written that way. Maybe the function Tft.drawString was written by a beginner too, eh?

GhostAction:
And this is the error I'm getting now: error: invalid conversion from 'const char*' to 'char*'
(for Tft.drawString(StepOne.c_str (), 0, 0, 1, BLACK):wink:

Whoever wrote that Tft library was not using best practices. Either that or they actually intend to write into your character string!
Edit the library sources to make the first argument to drawString() a 'const char *'. That will provide the compiler assurance that the function won't write into your character string making it safe to pass a "const char *". You can still pass a 'char *' so other code will still work.

The problem is I can't find the drawString function anywhere in the Tft library. I did find a drawChar function thing which I kinda used before so I'm just going to try to modify that.

Please post a link to where you got the library from.

I have this snippet of a script:

...

The problem is I can't find the drawString function anywhere in the Tft library.

That's why we don't like snippets. Usually the whole code gives a clue as to which library you are using.

I got it from here: http://www.seeedstudio.com/wiki/2.8''_TFT_Touch_Shield_V2.0

I can see drawString here:

Line 342:

void TFT::drawString(char *string,INT16U poX, INT16U poY, INT16U size,INT16U fgcolor)

Try making the first argument const.

You could save a lot of mucking around if you just use char arrays rather than the String class.

eg.

  char User [30] = "Logan";
  strcat (User, "'s Device");
  Serial.println (User);

Wow! That actually worked. Thanks!