How can I do the following in C ++? I enter the first word, for example "Help", then the second, for example "Lost" and put it on a given part of the words and then glue them. Like I had "HelLo"? Gluing I know how to do with the help of "strcat". Will you help how to do this?

  • 2
    If working with c-style strings is optional, then it is better to use the string class. - andrybak
  • thank. Can you give me a little example? Or just words to explain? The substr method I know. And bonding with something to reproduce? Strcat fit? - navi1893

1 answer 1

 string::erase string::append string::operator+= string::replace 

You can also see here .

If you need to use C-lines, you can see the list of functions here or in any reference book or textbook on C or C ++.

  • Thanks, helped! - navi1893
  • For good it is necessary to take the first character of the second and the last of the first word and while they are equal move to the end of the second and the beginning of the first. Then the remaining beginning of the first and the end of the second word “glue” (realistically, strcmp () will do). If the words turn out to be "mirror" to each other, then the result is an empty string. IMHO algorithm such, and with substr, strstr, etc. The natural program does not work. - avp
  • I think your option is more difficult. What's wrong with the substr ??? It seems to me personally that it will be much easier with him. - navi1893
  • @ Hashcode is good. I did not know) - navi1893
  • @ navi1893, you are right. Sorry, inattentively read your question. My algorithm for another task. Apparently, there is no way to do without nested loops. - avp 4:26 pm