Skip to content

Instantly share code, notes, and snippets.

@Jack2
Created November 27, 2012 15:32
Show Gist options
  • Save Jack2/4154840 to your computer and use it in GitHub Desktop.
Save Jack2/4154840 to your computer and use it in GitHub Desktop.
[C++]STL_vector_example
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> VS;
VS.push_back("Jack1");
VS.push_back("Jack2");
VS.push_back("Jack3");
cout << "Pushed Data" << endl;
for (int i=0; i<VS.size(); i++){
cout << VS[i] << endl;
}
return 0;
}
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> VS;
VS.push_back("Jack1");
VS.push_back("Jack2");
VS.push_back("Jack3");
cout << "Pushed Data" << endl;
//cout << VS.size() << endl; => 3
for (int i=0; i<VS.size(); i++){
cout << VS[i] << endl;
}
cout << "Reversed Data" << endl;
vector<string>::reverse_iterator re_iter;
for (re_iter=VS.rbegin(); re_iter!=VS.rend(); ++re_iter)
{
//cout << *VS.rbegin() << endl;
cout << *re_iter << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment