How to print vector's data

后端 未结 3 2063
不知归路
不知归路 2020-12-22 03:44

I\'ve searched a lot over the internet, and couldent find simple examples to print vector\'s data..

I tried to print it like an array, though it didnt worked...

3条回答
  •  余生分开走
    2020-12-22 04:10

    You have to iterate over the vector's elements and then brint each one :

    vector  testersName;
    // Fill your vector
    for (int i = 0; i < testersName.size(); ++i) {
        cout << testersName[i] << endl;
    }
    

    Moreover, I don't think the line vector testersName[MAX]; does what you think it does. It is not necessary to give a size to the vector because it grows dynamically when you fill it. If you still want to give a size, use parenthesis : (MAX)

提交回复
热议问题