String literals without prefix in C++ are of type const char[N]
. For example "abc"
is a const char[4]
. Since they're arrays, you can't concatenate them just like how you don't do that with any other array types like int[]
. "abc" + 1
is pointer arithmetic and not the numeric value converted to string then append to the previous string. Besides you can't have multiline strings like that. Either use multiple string literals, or use raw string literals R"delim()delim"
So to get the string like that the easiest way is to use a stream
std::ostringstream s;
s << R"(
<div class = "divTableRow">
<div class = "divTableCell">)" << j << R"(</div>
<div class = "divTableCell" id="tm")" << i << "b" << j << R"(">0</div>
<div class = "divTableCell" id="sm")" << i << "b" << j << R"(">0</div>
</div>
)";
auto ss = s.str();
const char *TableRow = ss.c_str();
You can also convert the integer value to string then concat the strings. Here's an example using multiple consecutive string literals instead of raw string literal:
using std::literals::string_literals;
auto s = "\n"
"<div class = \"divTableRow\">\n"
"<div class = \"divTableCell\""s + std::to_string(j) + "</div>\n"
"<div class = \"divTableCell\" id=\"tm" + std::to_string(i) + "b"s + std::to_string(j) + "\">0</div>\n"
"<div class = \"divTableCell\" id=\"sm" + std::to_string(i) + "b"s + std::to_string(j) + "\">0</div>\n"
"</div>\n"s;
const char *TableRow = s.c_str();
Remove using
and the s
suffix if you're an older C++ standard