Answer the question
In order to leave comments, you need to log in
How to concatenate strings and assign a value to a variable in a class?
I have a class
class Tampler
{
public:
Tampler();
private:
const char* m_sMyString;
};
#define TLDR_EXT ".tldr"
const char* GetCurrentDir();
const char *filename = "filename";
Answer the question
In order to leave comments, you need to log in
Excuse me, what's the problem? Depending on the situation, you can use both the C++ approach:
Tampler()
{
std::string str(GetCurrentDir());
str = str + filename + TLDR_EXT;
m_sMyString = strdup(str.c_str());
}
So is the C approach:Tampler()
{
char *tempstr = (char *)malloc(strlen(GetCurrentDir()) + strlen(filename) + strlen(TLDR_EXT) + 1);
strcpy(tempstr, GetCurrentDir());
strcat(tempstr, filename);
strcat(tempstr, TLDR_EXT);
m_sMyString = tempstr;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question