There is a strcat() function from the ported C library that will do "C style string" concatenation for you.
BTW even though C++ has a bunch of functions to deal with C-style strings, it could be beneficial for you do try and come up with your own function that does that, something like:
char * con(const char * first, const char * second) {
int l1 = 0, l2 = 0;
const char * f = first, * l = second;
// find lengths (you can also use strlen)
while (*f++) ++l1;
while (*l++) ++l2;
// allocate a buffer including terminating null char
char *result = new char[l1 + l2 + 1];
// then concatenate
for (int i = 0; i < l1; i++) result[i] = first[i];
for (int i = l1; i < l1 + l2; i++) result[i] = second[i - l1];
// finally, "cap" result with terminating null char
result[l1 + l2] = '\0';
return result;
}
...and then...
char s1[] = "file_name";
char *c = con(s1, ".txt");
... the result of which is file_name.txt
.
You might also be tempted to write your own operator +
however IIRC operator overloads with only pointers as arguments is not allowed.
Also, don't forget the result in this case is dynamically allocated, so you might want to call delete on it to avoid memory leaks, or you could modify the function to use stack allocated character array, provided of course it has sufficient length.