<
in the for
loop. If you put <=
you will certainly have touble!
int arr[100];
int i;
for(i=0; i<100; ++i) {
arr[i] = i * 10;
}
int foo[10] = {8,6,7,5,3,0,9};
char suits[4] = "SHCD"; // Spades, Hearts, Clubs, Diamonds
push_back
to insert an element at the end.
vector<int> foo;
for(int i=0; i<N; ++i) {
cin >> data;
foo.push_back(data);
}
vector<int> foo(100);
vector<int> foo(500,123);
foo.reserve(1000)
to pre-allocate space.int sum=0;
for(i = 0; i<foo.size(); ++i)
sum += foo[i]:
int sum=0;
for(auto i = foo.begin(); i != foo.end(); ++i)
sum += *i;
int sum=0;
for(auto i = foo.rbegin(); i != foo.rend(); ++i)
sum += *i;
typedefs
have evolved:typedef vector<int> vi;
typedef vector<vi> vvi;
pair<int,int> coord;
coord.first = 10;
coord.second = 999;
typedefs
for them too.typedef pair<int,int> ii;
typedef vector<ii> vii;