与全球矢量坏Alloc

时间:2018-02-13 20:13:50

标签: c++ vector

我想通过指令" 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++;
  }

}

1 个答案:

答案 0 :(得分:3)

string temp(temp.begin(), temp.end());

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

中使用时未初始化