Skip to content

Instantly share code, notes, and snippets.

@simonespa
Created August 10, 2020 17:32
Show Gist options
  • Select an option

  • Save simonespa/30be373c1a4c9c05941f89c346ad92a6 to your computer and use it in GitHub Desktop.

Select an option

Save simonespa/30be373c1a4c9c05941f89c346ad92a6 to your computer and use it in GitHub Desktop.
Vector test in C++
#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