#includeint main() { QVector myVector; myVector << 10 << 20 << 30 << 40 << 50; // Add elements to the vector int length = myVector.length(); // Get the length of the vector qDebug() << "My vector contains" << length << "elements."; }
My vector contains 5 elements.
#includeint main() { QVector myVector; myVector << "apple" << "banana" << "cherry" << "date" << "elderberry"; for (int i = 0; i < myVector.length(); i++) { qDebug() << "Element" << i << "is" << myVector.at(i); } }
Element 0 is "apple" Element 1 is "banana" Element 2 is "cherry" Element 3 is "date" Element 4 is "elderberry"From the above code examples, it can be determined that the QVector class is part of the Qt Core library.