#include#include
int main() { std::list mylist; mylist.push_back(1); // adds 1 to the end of the list mylist.push_back(2); // adds 2 to the end of the list mylist.push_back(3); // adds 3 to the end of the list // prints the list for (auto it = mylist.begin(); it != mylist.end(); ++it) { std::cout << *it << " "; } std::cout << std::endl; return 0; }
1 2 3
#include#include int main() { std::vector myvector; myvector.push_back(1); // adds 1 to the end of the vector myvector.push_back(2); // adds 2 to the end of the vector myvector.push_back(3); // adds 3 to the end of the vector // prints the vector for (auto it = myvector.begin(); it != myvector.end(); ++it) { std::cout << *it << " "; } std::cout << std::endl; return 0; }
1 2 3In both examples, the append function is achieved using the push_back function. The examples use different package libraries, with example 1 using the std::list library and example 2 using the std::vector library.