You are trying to concatenate string literals as if they are std::string
objects. They are not. In C++ string literals are of type const char[]
, not std::string
.
To join two string literals, place them next to each other with no operator:
const char* cat = "Hello " "world";
To join two std::string
objects, use operator+(std::string, std::string)
:
std::string hello("hello ");
std::string world("world\n");
std::sting cat = hello + world;
There is also an operator+
to join a string literal and a std::string
:
std::string hello("hello ");
std::string cat = hello + "world\n";
There is no operator+
that takes std::string
and int
.
A solution to your problem is to use std::stringstream
, which takes any operator<<
that std::cout
can take:
std::stringstream spath;
spath << "images/" << i << ".png";
std::string path = spath.str();