How to fix C/C++ 'size_t' does not name a type
Problem:
When compiling your C or C++ program. you see the following error message:
src/main.cpp:4:11: error: 'size_t' does not name a type
size_t mySize = 32;
Solution
In the file where the error occurs (in our example, that would be src/main.cpp
), add the following line at or near the top. It must be added before the line where size_t is first used, and usually you would add that line after the last existing #include
statements:
#include <stddef.h>
After adding that line, the error should be gone. Possibly you need to add said line to other files as well, so carefully check any compiler error messages if the error re-appears in other files.