Can I initialize an STL vector with 10 of the same integer in an initializer list?

后端 未结 6 1718
遇见更好的自我
遇见更好的自我 2021-01-31 07:54

Can I initialize an STL vector with 10 of the same integer in an initializer list? My attempts so far have failed me.

6条回答
  •  北海茫月
    2021-01-31 08:22

    can you post what you are doing

     int i = 100;
    vector vInts2 (10, i);
    
    vector::iterator iter;
    for(iter = vInts2.begin(); iter != vInts2.end(); ++iter)
    {
        cout << " i " << (*iter) << endl;
    }
    

提交回复
热议问题