Concatenation of strings

In vector c++, I have strings, for example : ACTT CTTG TTGA TG TGA GAG, as you can see, they superpose


So in the alignment we can see


I want to concatenate them as you can see above and put to another vector. I've tried use substring function, but it doesn't work...


Assuming you still use the same code as the last question you might want to consider using the first index you have in your element (it[0]). You could add this result to a string and print it.


std::string space = "";
std::string result = "";
auto end = vec.rend();

for(auto it = vec.rbegin(); it != vec.rend(); ++it ) {
    if (it == end - 1) {
        result += *it;
    else {
        result += it[0];

    std::cout << space << *it << std::endl;
    space += " ";
std::cout << result << std::endl;

Here's a fairly simple algorithm to overlap two strings:

#include <string>

std::string overlap(std::string first, std::string const & second)
    std::size_t pos = 0;
    for (std::size_t i = 1; i < first.size(); ++i)
        if ( - i, i, second, 0, i) == 0)
            pos = i;
    first.append(second, pos, second.npos);
    return first;


std::string result = overlap("abcde", "defgh");

And to overlap a whole range, use std::accumulate:

#include <algorithm>
#include <iostream>
#include <vector>

int main()
  std::vector<std::string> strings = {"abc", "def", "fegh", "ghq"};
  std::cout << std::accumulate(strings.begin(), strings.end(), std::string(), overlap) << std::endl;

Need Your Help

How to "grant create user" after enabling Oracle Vault

oracle oracle-vault

I need Oracle Vault for SSL database connection. After installing it, the "system" user is not allowed to create database users. How to grant the "create user" privilege to system after installing ...

Onchanged c# appending form

c# multithreading textbox

I am trying to append textbox everytime there is a change in my log text file in c#.