Cliff
Cliff

Reputation: 33

C++ displaying HTML code as a website (CGI Program)

I hope I explain this right.. but I need my C++ program to display an HTML website. The code that I have right now only displays the text. How do I make it so it is actually displayed like a website (using HTML code)? I am going to use the .exe file uploaded to a server to display the page.

#include <iostream>
using namespace std;

int main()
{
    cout << "Content-type: text/plain\n\n";
    cout << "<h2>My first CGI program</h2>\n";
    cout << "<h1>This is a test</h1>\n";
    cout << "<h3>Why is this not working</h3>\n";


    return 0;
}

Upvotes: 0

Views: 1299

Answers (1)

Joseph Mansfield
Joseph Mansfield

Reputation: 110658

Your HTTP response needs the status line, and you should change the mime type to text/html:

cout << "HTTP/1.1 200 OK\n";
cout << "Content-Type: text/html\n\n";
cout << "<h2>My first CGI program</h2>\n";
cout << "<h1>This is a test</h1>\n";
cout << "<h3>Why is this not working</h3>\n";

Upvotes: 2

Related Questions