Drawstring from array question


I’m very new to openframeworks but find I can do a lot of things already as I have been doing tons of stuff with Arduino, which helps tons. However, some very basic things (accompanied with vague error messages at best) I cannot get to work.

In this case I am trying to print a text on screen that is pulled from a char array, which is defined like so:
static constexpr char* sModeText[] = { “my text1”, “Slider”, “example 3”, “grid” };

I am using QT creator and this compiles fine in my app. However, when I use the drawstring command as so:

font.drawString(sModeText[1], 50, 50);

I get some errors about Symbol(s) not found for architecture. Unlike other errors this one is not pointing to a line in the code so I’m not even sure where to start looking to debug this…

Is my syntax incorrect? Or perhaps there is a better way of doing this in C++?

Thanks in advance for the help.

Welcome here.

You are using C style array and string. You can use the standard library instead:

vector< string > sModeText{ "my text1", "Slider", "example 3", "grid" };

For me this is a more modern style, a simpler syntax to learn, and less error prone. Perhaps not as optimized than old C code, but the loss is probably negligible here.

I don’t know why you got this error.

thanks, that seems to work! But now I have a next problem :wink: but this is solved.

Sometimes you may want to recycle code or to integrate c libs… (ie using ofxImGui)
Also, there’s some methods to convert these types:

std::string s;
std::stringstream ss;
chars array or even pointers



 // loaded string into char array
std::string inputText;
char tab[32];
strncpy(tab, inputText.c_str(), sizeof(tab));
tab[sizeof(tab) - 1] = 0;