Skip to content

Commit 745ff43

Browse files
committed
Include vector examples
1 parent 23ab996 commit 745ff43

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,11 @@ This example shows how to use two functions with same name. The only difference
180180
* `inline`
181181
* Use two different functions with same name
182182

183-
183+
#### Vector
184+
Some examples to show how to use vectors
185+
* Files
186+
* `vectorArg.cpp` - Show how to pass vector as an argument
187+
* Subjects
188+
* Vector as an arguments
189+
* `vector::push_back()`
190+
* `vector::size()`

vector/vectorArg.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <iostream>
2+
#include <vector>
3+
4+
//
5+
// Example passing a string vector as a parameter
6+
//
7+
8+
using namespace std;
9+
10+
int incVec (vector<string> & v)
11+
{
12+
13+
v.push_back("item 0");
14+
v.push_back("item 1");
15+
16+
return 0;
17+
}
18+
19+
int main (int argc, char* argv[])
20+
{
21+
vector<string> names;
22+
23+
int x = incVec(names);
24+
int s = names.size();
25+
26+
cout << "Size of vector: " << s << "\n";
27+
28+
for (int i = 0; i < s; i++)
29+
cout << names[i] << "\n";
30+
31+
}

0 commit comments

Comments
 (0)