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;
Printable View
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