0

I'm trying to use the StackString-library which offers not to eat up RAM over time by re-assigning values to strings. I started from scratch and wrote a very basic democode which works. Then I added an assignment to a STackString-variable from a normal string or a function with return-value string See code below If I try to compile I get a compiler-error saying no matching function for call to 'Stack::StackString<50>::append(String&)'

here is the code

#include <StackString.hpp> 
using namespace Stack;  // it is very important to have this line of code. Otherwise the code won't compile

StackString<50> myString = StackString<50>("Hello, World!");

String NormalString = "1234Test";

void setup() 
{ 
  Serial.begin(115200); 
  Serial.println();
  Serial.println();
  Serial.println(myString.c_str());

  myString.prepend("Everybody say: ");
  Serial.println(myString.c_str());

  myString.append(" How are you doing?");
  Serial.println(myString.c_str());
  Serial.println();

  //myString = NormalString;
  myString.append(NormalString);


}

void loop() 
{ // put your main code here, to run repeatedly:

}

Do I have to do some typecasting? and if yes how does it look like? WHat I want to do is assigning a StackString a new value. This means the STackString is on the left side of the "=" assigning operator. I have tried different variants to no avail.

Could this be a problem of the special construction as a "namespace" ? No idea no clue

you find the STackString-library here: https://gitlab.com/arduino-libraries/stackstring

best regards

Stefan

2
  • 1
    Are char arrays really so daunting that people go to this length to avoid them? Why struggle with this when you could just write a char array and be done with it?
    – Delta_G
    Sep 9 '20 at 23:06
  • You are writing this from a position of beeing an expert about arrays of char, c-strings etc. This does explain nothing to come nearer to the point of enough knowledge to use your preferred way of using "strings". So a much more productive comment would be to explain how it works. Not with a most short and elegant single line of code but with a thoroughly explained example with lots of comments or additional text.
    – StefanL38
    Sep 11 '20 at 4:03
0

StackString doesn't know what a String is. The append function only accepts a const char *, a const char or an int:

void append(const char* string);
void append(const char character);
void append(int number);

You can get a const char * from a String easily enough with .c_str(), so use that in the append:

myString.append(NormalString.c_str());

There is also no simple assignment (or complete content replacement) with StackString - you have to "clear" the string first. So to replace the content with what is in NormalString you would:

myString.clear();
myString.append(NormalString.c_str());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.