oki folks I got some doubts about he following code:
When I compile it against g++ -Wall it reports the following errors:Code://Creating a vector that holds integers #include <iostream> #include <vector> using namespace std; int main(void){ vector<int> v; for (int i = 0; i < 10; i++) v.push_back(i); for (int i = 0; i < v.size(); i++) cout << v[i] << ", "; cout << endl; for (int i = 0; i < v.size(); i++) v[i] = v[i] * 10; cout << v[i] << ", "; cout << endl; }
intvector.cpp: In function `int main()':
intvector.cpp:10: warning: comparison between signed and unsigned integer
expressions
intvector.cpp:13: warning: comparison between signed and unsigned integer
expressions
intvector.cpp:15: error: name lookup of `i' changed for new ISO `for' scoping
intvector.cpp:13: error: using obsolete binding at `i'
So basically I got 2 questions:
1º should I use my for variables as unsigned ints?
2º why is the use of i to all loops invalid? is the book wrong?
Thanks in advance.