我用我的程序載體是這樣的:無法訪問存儲在C++矢量
vector<vector<string> > values;
values[0].push_back("test words");
當我運行的代碼,它顯示「段故障」
然後我嘗試gdb它和我得到這個:
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000008
0x00000001000035be in std::vector<std::string, std::allocator<std::string> >::push_back (this=0x0, [email protected]) at stl_vector.h:602
602 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
這是怎麼回事?
THX,但我認爲當我創建載體將初始化。 – MrROY
@MrROY,它會自行初始化,但不會插入默認元素。 – hmjd