// example from https://en.cppreference.com/w/cpp/container/vector/vector // // added comments to the print vector function, RP // #include #include #include // added this and removed std:: throughout, RP: // using namespace std; // print vector, comments show alternative/equivalent statements // template ostream& operator<<(ostream& s, const vector& v) { s.put('['); // s << '['; char comma[3] = {'\0', ' ', '\0'}; // string comma = ""; for (const auto& e : v) { s << comma << e; comma[0] = ','; // comma = ", "; } return s << ']'; // s << ']'; return s; } int main() { // c++11 initializer list syntax: vector words1 {"the", "frogurt", "is", "also", "cursed"}; cout << "words1: " << words1 << '\n'; // words2 == words1 vector words2(words1.begin(), words1.end()); cout << "words2: " << words2 << '\n'; // words3 == words1 vector words3(words1); cout << "words3: " << words3 << '\n'; // words4 is {"Mo", "Mo", "Mo", "Mo", "Mo"} vector words4(5, "Mo"); cout << "words4: " << words4 << '\n'; // added this, RP: // vector v { 1, 2, 3}; cout << "v: " << v << endl; }