Home  /  Documentation  /  Examples  /  std::string demo

std::string demo

The code below demonstrates std::string usage with Node++ functions and macros.

Both string styles can coexist in harmony even in the same OUT calls.

npp_app.h

#define NPP_CPP_STRINGS

npp_app.cpp

void npp_app_main() { OUT_HTML_HEADER; OUT("<h1>%s</h1>", NPP_APP_NAME); /* display form */ OUT("<p>Please enter your name:</p>"); OUT("<form action=\"welcome\"><input name=\"name\" autofocus> <input type=\"submit\" value=\"Run\"></form>"); /* try to get the query string value */ QSVAL qs_name_c; // C-style query string value std::string qs_name_cpp; // C++ string query string value if ( QS("name", qs_name_c) ) // if present, bid welcome OUT("<p>Welcome %s, my dear C-style friend!</p>", qs_name_c); if ( QS("name", qs_name_cpp) ) // read name again into the second variable OUT("<p>Welcome %s, my dear C++ friend!</p>", qs_name_cpp); if ( QS("name", NULL) ) // now only check for presence OUT("<p>Welcome %s and %s, my dear friends!</p>", qs_name_c, qs_name_cpp); OUT_HTML_FOOTER; }