char b = (char)i;
char *text = "function make_page("+b+"){"
"var url = 'http://www.gigasena.com.br/loterias/mega-sena/resultados/resultado-mega-sena-'+"+b+"+'.htm';"
"var page = require('webpage').create();"
"var fs = require('fs');"
"page.open(url, function () {"
"page.evaluate(function(){"
""
"});"
"page.render('results/export-'+"+b+"+'.png');"
"fs.write('results/'+"+b+"+'.html', page.content, 'w');"
"phantom.exit();"
"});"
"}"
"make_page("+b+");";
答案 0 :(得分:5)
您无法在C ++中添加字符串文字。如果您使用std::string
对象,则可以执行以下操作:
int i = 'a';
char b = (char)i;
std::string text = std::string("function make_page(") + b + "){"
"var url = 'http://www.gigasena.com.br/loterias/mega-sena/resultados/resultado-mega-sena-'+" + b + "+'.htm';"
"var page = require('webpage').create();"
"var fs = require('fs');"
"page.open(url, function () {"
"page.evaluate(function(){"
""
"});"
"page.render('results/export-'+" + b + "+'.png');"
"fs.write('results/'+" + b + "+'.html', page.content, 'w');"
"phantom.exit();"
"});"
"}"
"make_page(" + b + ");";
答案 1 :(得分:1)
您不能在两个c字符串上使用operator +。你可以用这个:
http://en.cppreference.com/w/cpp/string/byte/strcat
或者你可以这样做:
char b;
std::string text = std::string("your text here") + b + std::string("more text etc");
//then use text.c_str() if you need const char*