When to use std::size_t?

I’m just wondering should I use std::size_t for loops and stuff instead of int?
For instance:

#include <cstdint>

int main()
{
    for (std::size_t i = 0; i < 10; ++i) {
        // std::size_t OK here? Or should I use, say, unsigned int instead?
    }
}

In general, what is the best practice regarding when to use std::size_t?

14 Answers
14

Leave a Comment