串接 在向量C++中,我有字符串,例如: ACTT CTTG TTGA TGA嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎 ACTT CTTG TTGA TG GAG

串接 在向量C++中,我有字符串,例如: ACTT CTTG TTGA TGA嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎嘎 ACTT CTTG TTGA TG GAG,c++,string,vector,C++,String,Vector,所以在排列中我们可以看到 ACTTGAG 我想把它们连接起来,就像你们在上面看到的,然后放到另一个向量上。我已经尝试使用子字符串函数,但它不起作用。假设您仍然使用与您希望使用的元素中的第一个索引相同的代码( IT(0)< /代码>)。您可以将此结果添加到字符串并打印它 使用: std::string space=“”; std::string result=“”; 自动结束=vec.rend(); for(auto it=vec.rbegin();it!=vec.rend();++it){ 如

所以在排列中我们可以看到

ACTTGAG

我想把它们连接起来,就像你们在上面看到的,然后放到另一个向量上。我已经尝试使用子字符串函数,但它不起作用。

假设您仍然使用与您希望使用的元素中的第一个索引相同的代码(<代码> IT(0)< /代码>)。您可以将此结果添加到字符串并打印它

使用:

std::string space=“”;
std::string result=“”;
自动结束=vec.rend();
for(auto it=vec.rbegin();it!=vec.rend();++it){
如果(it==end-1){
结果+=*it;
}
否则{
结果+=它[0];
}        

STD::CUT

假设您仍然使用与您可能要考虑的元素相同的代码,使用元素中的第一个索引(<代码> IT [0 ] < /代码>)。可以将此结果添加到字符串并打印它。

使用:

std::string space=“”;
std::string result=“”;
自动结束=vec.rend();
for(auto it=vec.rbegin();it!=vec.rend();++it){
如果(it==end-1){
结果+=*it;
}
否则{
结果+=它[0];
}        

STD::CUT

假设您仍然使用与您可能要考虑的元素相同的代码,使用元素中的第一个索引(<代码> IT [0 ] < /代码>)。可以将此结果添加到字符串并打印它。

使用:

std::string space=“”;
std::string result=“”;
自动结束=vec.rend();
for(auto it=vec.rbegin();it!=vec.rend();++it){
如果(it==end-1){
结果+=*it;
}
否则{
结果+=它[0];
}        

STD::CUT

假设您仍然使用与您可能要考虑的元素相同的代码,使用元素中的第一个索引(<代码> IT [0 ] < /代码>)。可以将此结果添加到字符串并打印它。

使用:

std::string space=“”;
std::string result=“”;
自动结束=vec.rend();
for(auto it=vec.rbegin();it!=vec.rend();++it){
如果(it==end-1){
结果+=*it;
}
否则{
结果+=它[0];
}        

std::cout这里有一个相当简单的算法来重叠两个字符串:

#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 (first.compare(first.size() - i, i, second, 0, i) == 0)
        {
            pos = i;
        }
    }
    first.append(second, pos, second.npos);
    return first;
}
要覆盖整个范围,请使用
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;
}
#包括
#包括
#包括
int main()
{
向量字符串={“abc”、“def”、“fegh”、“ghq”};

std::cout这里有一个相当简单的算法来重叠两个字符串:

#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 (first.compare(first.size() - i, i, second, 0, i) == 0)
        {
            pos = i;
        }
    }
    first.append(second, pos, second.npos);
    return first;
}
要覆盖整个范围,请使用
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;
}
#包括
#包括
#包括
int main()
{
向量字符串={“abc”、“def”、“fegh”、“ghq”};

std::cout这里有一个相当简单的算法来重叠两个字符串:

#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 (first.compare(first.size() - i, i, second, 0, i) == 0)
        {
            pos = i;
        }
    }
    first.append(second, pos, second.npos);
    return first;
}
要覆盖整个范围,请使用
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;
}
#包括
#包括
#包括
int main()
{
向量字符串={“abc”、“def”、“fegh”、“ghq”};

std::cout这里有一个相当简单的算法来重叠两个字符串:

#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 (first.compare(first.size() - i, i, second, 0, i) == 0)
        {
            pos = i;
        }
    }
    first.append(second, pos, second.npos);
    return first;
}
要覆盖整个范围,请使用
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;
}
#包括
#包括
#包括
int main()
{
向量字符串={“abc”、“def”、“fegh”、“ghq”};



std::你想建立一个最短的字符串,其中每个字符串都是子字符串吗?你说“它不工作”是什么意思?我一直在使用substr,它对我很好。什么不工作?你尝试过什么?我想你应该看看这些东西,当我使用su时,遍历trie可能会帮助你得到你想要的东西B字符串,我不知道如何更全面地使用它来表示字符串,当它们的长度不同时。你想创建最短的字符串,其中每个字符串都是子字符串?你说“它不工作”是什么意思?我一直使用substr,它对我来说很好。什么不工作?你尝试过什么?我想你应该看看当我使用子字符串时,我不知道如何在字符串中更全局地使用它,当它们的长度不同时,你想构建最短的字符串,其中每个字符串都是子字符串?你说“它不工作”是什么意思?我一直使用子字符串,它工作很好ne对我来说…什么不起作用?你试过什么?我想你应该看看这些东西遍历trie可能会帮助你得到你想要的东西当我使用子字符串时,我不知道如何对字符串更全局地使用它,当它们的长度不同时你想构建最短的字符串,其中每个字符串都是子字符串字符串?什么是“它不起作用”?我一直在使用substr,它对我来说很好..什么不起作用?你试过什么?我想你应该看看这些东西遍历trie可能会帮助你得到你想要的东西当我使用substring时,我不知道如何在字符串中更全局地使用它,当它们的长度不同时,但是嗯,我用了子字符串,有些字符串比较短,我不知道如何连接它们way@AirelleJab用一个更好的例子更新了答案非常感谢,但我还有一个问题-我有一个编译问题,因为结果+=it中运算符“+=”不匹配,运算符“+”也是unavaliable@AirelleJab糟糕的是,我打错了:)第一个“+=it;”应该是:“+=*it;”。工作示例:不幸的是,它一个接一个地打印所有字符串:(是的,但当我在其中使用子字符串时,有些字符串更短,我不知道如何将它们连接在一起。)way@AirelleJab用一个更好的例子更新了答案非常感谢,但我还有一个问题-我有一个编译问题,因为结果+=it中运算符“+=”不匹配,运算符“+”也是unavaliable@AirelleJab糟糕的是,我输入了一个错误:)第一个“+=it;”应该是:“+=*it;”。工作示例:不幸的是,它一个接一个地打印所有字符串:(是的,但是当我在其中使用子字符串时,一些字符串更短,我不知道如何将它们连接到一起way@AirelleJab通过打赌更新答案