For example, something like this:
#include <string> #include <iostream> #include <windows.h> int main() { std::string sl; char WindowText[4096] = "***"; sl = "Window Text = '"; sl += WindowText; sl += "'! Some Text"; MessageBoxA(0, sl.c_str(), "Some Title" ,MB_ICONERROR | MB_OK); return 0; }
UPD: At the request of a colleague I will add a little answer. Since the C ++ tag was indicated in the question, I give an example with the simplest constructs from this language with the maximum preservation of the entities from the question (of course, it would be better to replace all strings with the type std::string ). And of course, this is not the only possible option.
In C ++, for user-defined data types, and in particular, for classes and structures, it is possible to override (overload) the behavior of standard operations. In the case of the string class from the standard template library, the + (and += ) operator is redefined to concatenate such strings with objects of the same type and with C-style strings. In order for the compiler to use this overloaded operator it is necessary that at least one of the two operands belong to this type of string .
If you remain within the framework of the standard C library, you could use the functions I already mentioned in the comments to form the sprintf()/snprintf() string, the functions mentioned by Harry for concatenating strcat()/strncat() and even functions for copying / move strcpy()/strncpy()/memcpy()/memmove() . Preference should be given to those variants of functions where the letter has the letter n (this does not apply to memcpy()/memmove() , because the size must also be explicitly indicated in them) - these functions, as it were (in the sense of providing an opportunity, and the rest depends on the programmer), protected from overflow errors, since the size of the target memory block must be explicitly stated.
Window Textone word and without a space? So, as indicated in thechar WindowText[4096]declarationchar WindowText[4096]... - VladimirС++ != С# && != Java:) - NewView