C++ size()

vector, string,等的size()返回的都是无符号的整数,跟负数比较会出问题,比如

vector<int> a{1, 4, 3};
int i = -1;
while (i < a.size()) {
    cout << "great" << endl;//并不会输出
    break;
}

#必须改成
while (i < (int)a.size()) {

 

0