I am having trouble concatenating 2 chars
what is the proper way of doing something like this?Code:char a = 'a'; char b = 'b'; strcat (a,b); cout << a;
This is a discussion on Concatination of chars within the C++ Programming forums, part of the General Programming Boards category; I am having trouble concatenating 2 chars Code: char a = 'a'; char b = 'b'; strcat (a,b); cout << ...
I am having trouble concatenating 2 chars
what is the proper way of doing something like this?Code:char a = 'a'; char b = 'b'; strcat (a,b); cout << a;
You can't concatenate two chars into a string of two chars unless you have a string to store it in [and strcat do not take inputs of char anyways].
Either of these would work:
Using C++ properly:
or standard C with a bit of C++ for output:Code:string a("a"); string b("b"); a += b; // or a = a + b; if you like typing a lot. cout << a;
Or using indexes to arrays:Code:char a[3] = "a"; char b[2] = "b"; strcat(a, b); cout << a;
--Code:char a[3] = "a"; char b = 'b'; a[1] = b; a[2] = 0; // Just in case. It should really be zero from the a[3] = "a"; line. cout << a;
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.