I'm developing a webserver using C++ and I want a string array to contain the HTML code of my HTML elements.
In the definition of that array, I want to supplement hard-coded characters with strings that are defined in other arrays.
For example, my webpages[]
array would contain the HTML for each webpage and be defined as:
string webpages[NUM_WEBPAGES] =
{
...
"<p>Please <a href=\"" + urls[PAGE_LOGIN] + "\">login here</a></p>",
...
};
However, the HTML that gets sent to the client is:
<p>Please <a href="">login here</a></p>
As you can see, the url from urls[PAGE_LOGIN]
was not populated into the HTML.
I have confirmed via code inspection and gdb that urls[PAGE_LOGIN]
has the value /login
.
(1) Why is this not working?
(2) Is this possible?
(3) If no, any recommendations?
Thank you!
EDIT: Minimal reproducible code example... because I don't know how to stackoverflow.
Also my C++ is bad.
webpages.h:
enum webpage
{
PAGE_LOGIN,
NUM_WEBPAGES
};
extern string webpages[NUM_WEBPAGES];
webpages.cpp:
string webpages =
{
"<p>Please <a href=\"" + urls[PAGE_LOGIN] + "\">login here</a></p>",
};
urls.h:
extern string urls[NUM_WEBPAGES];
urls.cpp:
string urls[NUM_WEBPAGES] =
{
"/login"
};
Please login here
" No compiler warnings. Compiling with -Wall. – Ashley Oct 13 '19 at 00:56