我有代码应该将一个字符串分成 3 个长度部分:
ABCDEFG should be ABC DEF G
但是,我有一个非常长的字符串,而且我不断得到 p>
terminate called without an active exception
当我缩短字符串的长度时,它似乎起作用了。我需要更多空间吗?我认为在使用字符串时我不必担心空间问题。
int main ()
{
string code, default_Code, start_C;
default_Code = "TCAATGTAACGCGCTACCCGGAGCTCTGGGCCCAAATTTCATCCACT";
start_C = "AUG";
code = default_Code;
for (double j = 0; j < code.length(); j++) { //insert spacing here
code.insert(j += 3, 1, ' ');
}
cout << code;
return 0;
}
最佳答案
考虑一下 code.length() == 2 的情况。您在字符串的某处插入了一个空格。我不确定,但如果 for(int j=0; j+3 < code.length(); j++)
就可以了.
关于c++ - 我需要更多空间吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8132437/