Created
November 27, 2012 15:32
-
-
Save Jack2/4154840 to your computer and use it in GitHub Desktop.
[C++]STL_vector_example
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; | |
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; | |
} |
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; | |
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