与全球矢量的不良同种

Bad Alloc with Global Vector

本文关键字:不良      更新时间:2023-10-16

我想通过指令" iinc(10,20(",我想在指令中添加每个数字。因此,我的全球向量应为< 10>< 20>之后。我的运行时间错误说

terminate called after throwing an instance of 'std::bad_aloc' 
what(): std:: bad_aloc
aborted

代码:

vector<int> number_list;
void add_number(string input)
{
int count = 5;
vector<char> trythis;
 while(input[count] != ')')
 {
    do{ 
      trythis.push_back(input[count];
      count++;
    }while(input[count] != ',');
    string temp(trythis.begin(), trythis.end());
    int real = atoi(temp.cstr());
    number_list.push_back(real);
    count++;
  }
}
string temp(temp.begin(), temp.end());

变量'temp'在其自己的初始化中使用

时将不专门化