Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 17 Online
OpenStudy (anonymous):

concatination of two strings: string a1[1]={"cat"}; string a2[1]={"dog"}: string concatenate_a1_a2[1]; how to concatinate the above two strings?

OpenStudy (anonymous):

strcat can be used for char pointer but here i have string. how to join the together?????

OpenStudy (anonymous):

strcat should work I think, but idk since i don't use c++ but another way to do is just make a loop and add chars together :D

OpenStudy (anonymous):

Under the hood, isn't the string type just a char *? I do think strcat should work for string also. Is the 1 in your declaration? Doesn't that mean that you are declaring three arrays of string, each with size 1? Then, what would happen, is that you aren't trying to concatenate two strings, but rather two arrays of string. But I don't really know C++, just wild guessing here

OpenStudy (anonymous):

well if i understood right what you want... just use '+' perand on the 2 strings as operators conc = string a1[1] + string a2[1]. I hope it helped.

OpenStudy (anonymous):

you can union two strings without operator just see code. string s1 = "cat"; string s2 = "dog"; string conc = s1 + s2; because if you want union strings using array you must allocate memory

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!