Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 为什么我的代码需要一个格式化的DNA并将其转换成一个载体,却在运行时崩溃了_C++_Bioinformatics - Fatal编程技术网

C++ 为什么我的代码需要一个格式化的DNA并将其转换成一个载体,却在运行时崩溃了

C++ 为什么我的代码需要一个格式化的DNA并将其转换成一个载体,却在运行时崩溃了,c++,bioinformatics,C++,Bioinformatics,我在代码块和cygwin中编译,但在运行时它崩溃了。 source.txt文件的格式如下: >样本1 ACTG GCA GTC >样本2 TAACG GGCC dtb应该是这样的: dtb=(样本1、ACTGGCAGTC、样本2、TAACGGGCC) #包括 #包括 #包括 #包括 使用名称空间std; int main() { ifstreammyfile; int i=0; 字符串seq=“”,holder=“”; myfile.open(“source.txt”); 向量dtb; whil

我在代码块和cygwin中编译,但在运行时它崩溃了。
source.txt文件的格式如下:

>样本1
ACTG
GCA
GTC
>样本2
TAACG
GGCC
dtb应该是这样的:
dtb=(样本1、ACTGGCAGTC、样本2、TAACGGGCC)

#包括
#包括
#包括
#包括
使用名称空间std;
int main()
{
ifstreammyfile;
int i=0;
字符串seq=“”,holder=“”;
myfile.open(“source.txt”);
向量dtb;
while(myfile>>seq)
{
如果(序号substr(0,1)==“>”)
{
dtb[i]=序列子序列(1,序列长度()-1);
i++;
如果(i!=0)
dtb[i]=持有人;
持有人=”;
}
其他的
{
持有人+=序号;
}
}
cout一个对象开始时是空的。这意味着其中的任何索引都将超出范围,并导致未定义的行为


您需要使用例如..

向向量添加元素,解决此类问题的正确工具是调试器。在询问堆栈溢出问题之前,您应该逐行检查代码。有关更多帮助,请阅读。至少,您应该[编辑]您的问题包括一个重现您的问题的示例,以及您在调试器中所做的观察。
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
int main()
{
    ifstream myfile;
    int i=0;
    string seq="",holder="";
    myfile.open("source.txt");
    vector<string> dtb;
    while (myfile>> seq)
    {
        if (seq.substr(0,1)==">")
        {
            dtb[i]=seq.substr(1,seq.length()-1);
            i++;
            if (i!=0)
                dtb[i]=holder;
            holder="";
        }
        else
        {
            holder+=seq;
        }
    }
    cout<<dtb[0]<<"\n"<<dtb[1]<<"\n"<<dtb[2]<<"\n"<<dtb[3];
    return 0;
}