ccplusplus.com
Learn C, C++ Concepts
Saturday, November 12, 2011
vector example c++
/*********************************************************************** * File : vector.cpp * Author : Saurabh Gupta * Desc : vector example c++ * Source : http://saurabhgupta0527.blogspot.com/2011/10/standard-template-library.html * Created : PM 06:57 12 November 2011 * Note : ************************************************************************/ #include <iostream> #include <vector> using namespace std; int main() { vector <int> coll; //vector container for integer elements // append elements with values 1 to 6 for (int i=1; i<=6; ++i) { coll.push_back(i); } //print all elements followed by a space for (int i=0; i<coll.size( ); ++i) { cout << coll[i] << ' '; } cout << endl; } /* * * [sgupta@rhel55x86 stl]$ c++ vector.cpp -o vector [sgupta@rhel55x86 stl]$ ./vector 1 2 3 4 5 6 [sgupta@rhel55x86 stl]$ */
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment