Convert dynamic string to char*

I'm pretty green in C++ language.

I have these lines:

char* OutPath;
OutPath = "/home/Master/Electricity" + kamstrings[kreg] + "/state";

It's used in a loop where kreg is an integer and kamstrings is an array.

The error I get is:

error: invalid operands of types ‘const char [25]’ and ‘char*’ to binary ‘operator+’

I've been Googling all evening and can't find any solutions to this.

In end OutPath should be a topic for the PubSubClient (MQTT) library.

Never mind.

This is my current - working - solution.

String kamReg = String(kamstrings[kreg]);
String tmpPath = String("/home/Master/Electricity/" + kamReg + "/state");
	
char buf[100];
tmpPath.toCharArray(buf,100);
	
char* OutPath;
OutPath = buf;

This is my current - working - solution.

That approach will, sooner or later, bite you in the ass. Learn how to properly use strings, and forget that the String abomination (oops, I meant class) exists.

You can NOT add strings (using the + operator). You could concatenate strings, using strcat() or other ways.