This question already has an answer here:
This code throws a warnings when I compile it under windows. Any solutions?
#include<vector>
int main(){
std::vector<int> v;
//...
for (int i = 0; i < v.size(); ++i) { //warning on this line
//...
}
}
Say
std::size_t i = 0;
:Replace all the definitions of
int i
withsize_t i
.std::vector<T>::size()
returns the typesize_t
which is unsigned (since it doesn't make sense for containers to contain a negative number of elements).You could also use iterators instead to avoid the potential for a warning altogether:
Or if you're using C++11: