Skip to content

Instantly share code, notes, and snippets.

@HyodaKazuaki
Last active July 13, 2017 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HyodaKazuaki/1dd00bf7a97b4912c0be5b087751cb9d to your computer and use it in GitHub Desktop.
Save HyodaKazuaki/1dd00bf7a97b4912c0be5b087751cb9d to your computer and use it in GitHub Desktop.
C++でのCGIプログラム
#include <stdio.h>
#include <stdarg.h>
template <typename ... Args>
void cprintf(const char *format, Args const & ... args);
int main(void)
{
cprintf("Content-type: text/html");
cprintf("");
cprintf("<!DOCTYPE HTML>");
cprintf("<html lang=\"ja\">");
cprintf("<head>");
cprintf("<meta charset=\"UTF-8\">");
cprintf("<title>Test Page</title>");
cprintf("</head>");
cprintf("<body>");
cprintf("<h1>Test page</h1>");
cprintf("<p>");
cprintf("This is test page.<br>");
cprintf("テストページ");
cprintf("</p>");
cprintf("</body>");
cprintf("</html>");
return 0;
}
template <typename ... Args>
void cprintf(const char *format, Args const & ... args)
{
char s[4095];
sprintf(s, "%s\r\n", format);
printf(s, args ...);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment