jeudi 24 décembre 2020

using size_t inside for loop throwing error "std::length_error"

I had encountered an error inside for loop, if str.size() = 1 then it's throwing error as

terminate called after throwing an instance of 'std::length_error'
what(): basic_string::_M_create

but if str.size() is anything more than 1 then everything goes well. Also when I changed size_t to int everything goes fine. Why?

for (size_t i = str.size() - 1; i >= 0; i--)
        excess3(str[i]);

Here str is vector of string

Aucun commentaire:

Enregistrer un commentaire