Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
Vector examples....
//clang 3.8.0 #include <iostream> #include <vector> using namespace std; class P { public: P(int p):i(p) { } int getElem() {return i;} private: int i; }; int main() { cout << "Hello, world!\n"; int a =10, b = 20, c = 30; vector<int> vi; vi.push_back(a); vi.push_back(b); vi.push_back(c); for(auto elem: vi) cout << elem << endl; cout << endl; vector<int*> vip; vip.push_back(&a); vip.push_back(&b); vip.push_back(&c); for(auto ip: vip) cout << *ip << endl; cout << endl; vector<P> vp; vp.push_back(P(100)); vp.push_back(P(200)); vp.push_back(P(300)); for(auto elem: vp) cout << elem.getElem() << endl; cout << endl; vector<P*> vpp; vpp.push_back(new P(1000)); vpp.push_back(new P(2000)); vpp.push_back(new P(3000)); for(auto elem: vpp) cout << elem->getElem() << endl; cout << endl; vector<P*>::iterator vectorBeginIter = vpp.begin(); vector<P*>::iterator vectorEndIter = vpp.end(); while(vectorBeginIter != vectorEndIter) { cout << (*vectorBeginIter)->getElem() << endl; vectorBeginIter++; } cout << endl; }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
C++ does not have reference-to-reference types
Composite pattern
Derivation of the 0x9E3779B97F4A7C17u constant
hello,world !ssn2019
Own initialization
Program to Time Difference
SceneGraph Interviewee Task
regex
user defined exception
problem_name_1
stackse - search stackoverflow differently
Please log in to post a comment.