#include <cstdio>
#include <string>
constexpr size_t MAX_LEN = 512;
int main()
{
std::string imageFileName = "/image/file/name";
imageFileName.resize(MAX_LEN);
// ...
if (auto len = imageFileName.size(); len >= MAX_LEN)
{
printf("File path %s is too long (max len: %lu): %lu\n",
imageFileName.c_str(), MAX_LEN, len);
return EXIT_FAILURE;
}
printf("File path %s is valid\n", imageFileName.c_str());
// ...
}