CString + CString

How can I join two cstring


C:\USERS\****\Desktop


and

\


TO MAKE IT C:\USERS\****\Desktop\


1
2
3
CString foo = "C:\\USERS\\****\\Desktop";

foo += "\\";
I think he means a pointer to a char.

You can add them like this I believe:
1
2
3
4
5
char* cstr = "Fred is a boss";

char* cstr2 = "It's true";

char* cstr3 = cstr cstr2;


If that doesn't work, instead of the last line do this:

char* cstr3 = cstr + cstr2;
closed account (1yR4jE8b)
I think he means a pointer to a char.


Probably not because CString is a very specific thing in Windows programming.

This is probably what OP is looking for:
http://msdn.microsoft.com/en-us/library/vstudio/72b2swax.aspx#_core_concatenating_two_cstring_objects

That said, this probably belongs in Windows programming.
None of that will work, Fredbill.

If you're unsure, please test your answer before supplying it.
char* cstr3 = cstr cstr2;

No. This is not legal C or C++.

char* cstr3 = cstr + cstr2;

No. This is not legal C or C++.

Please don't confuse the people who are trying to learn C++ by posting incorrect information.
Last edited on
I got it to work with this

CString coke2 = m_var4 + "\\" + s2;

by putting two \\..it works as one
by putting two \\..it works as one

Yes, that should work. The first \ is called an escape character.
I think the strcpy() and strcat() functions from the standard library will concatenate strings. For example:
1
2
3
4
5
char * name [81];
strcpy(name,"Archie");
strcat(name," ");
strcat(name,"Bolter");
printf("%s, he my friend.\n",name);   //prints     Archie Bolter, he my friend. 
He's talking about CStrings, not char arrays.
Topic archived. No new replies allowed.