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+");";
Asked
Active
Viewed 7,078 times
-3

Arthur Yakovlev
- 8,933
- 8
- 32
- 48
-
You can't add string literals... – crashmstr Jun 03 '15 at 17:43
-
2You´re mathematically adding a character to a memory address here (at least you want to). Don´t confuse C or C++ with eg. Java, and decide for one language (C "or" C++), then we can show you something correct. – deviantfan Jun 03 '15 at 17:43
2 Answers
5
You cannot add string literals in C++. If you use a std::string
object then you can do:
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 + ");";

NathanOliver
- 171,901
- 28
- 288
- 402
2
You cannot use operator+ on two c strings. You can use this:
http://en.cppreference.com/w/cpp/string/byte/strcat
Or you can do something like this:
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*

Josh Edwards
- 369
- 1
- 4