Created
August 10, 2020 17:32
-
-
Save simonespa/30be373c1a4c9c05941f89c346ad92a6 to your computer and use it in GitHub Desktop.
Vector test in C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <string> | |
| using namespace std; | |
| void vectorTest(); | |
| int main() { | |
| vectorTest(); | |
| } | |
| void vectorTest() { | |
| vector<string> vec; | |
| vec.push_back("Simone"); | |
| vec.push_back("Frank"); | |
| vec.push_back("Sarah"); | |
| // iterate with index | |
| for (int i = 0; i < vec.size(); i++) { | |
| cout << vec[i] << endl; | |
| } | |
| cout << endl; | |
| // iterate with iterator | |
| vector<string>::iterator it; | |
| for (it = vec.begin(); it != vec.end(); it++) { | |
| cout << *it << endl; | |
| *it += "XXX"; | |
| } | |
| cout << endl; | |
| for (it = vec.begin(); it != vec.end(); it++) { | |
| cout << *it << endl; | |
| *it += "XXX"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment