HTML

P

Peter Morris

Is it possible to use C or C++ to create web pages?

Ouputting text with HTML syntax is easy enough,
but how do I make a web browser see the generated
text?
 
M

MiniDisc_2k2

Peter Morris said:
Is it possible to use C or C++ to create web pages?

Ouputting text with HTML syntax is easy enough,
but how do I make a web browser see the generated
text?

Sorry about the os-dependent reply, but this question is kind of
os-dependent (OP, please, next time, try to place this in a better
newsgroup). Just because I'm feeling nice:

(Assuming windows)

#include <fstream>
#include <stdlib.h>

int main()
{
using namespace std;

/* Output to text file the HTML stuff here */

system("iexplore <filename>");
}

Obviously, replace <filename> with whatever file you sent it to. This should
open up internet explorer to view the newly created file. Note that you need
to output this code to a file with a .htm or .html extention!
 
M

Michael Furman

Peter Morris said:
Is it possible to use C or C++ to create web pages?

Ouputting text with HTML syntax is easy enough,
but how do I make a web browser see the generated
text?

Just output it in the file and then start browser and tell it to read this
file.

Michael Furman
 
P

Peter Morris

Michael Furman said:
Just output it in the file and then start browser and tell it to read this
file.

Michael Furman

If that's all I wanted, I could just write the HTML file myself.

In Perl, for instance, I can write a script that outputs HTML.
If I run the script, it outputs the text to the screen. But I
can point Internet Explorer at the script, and it displays
a web page. This is dynamically generated, it varies according
to data read from a database.

I've written an application in perl, but I want to port it to
C++ or similar, using a complied executable instead of a
Perl script.
 
R

Russell Hanneken

Peter Morris said:
If that's all I wanted, I could just write the HTML file myself.

In Perl, for instance, I can write a script that outputs HTML.
If I run the script, it outputs the text to the screen. But I
can point Internet Explorer at the script, and it displays
a web page. This is dynamically generated, it varies according
to data read from a database.

I don't know how you've configured things, but that doesn't work for me
unless I access the Perl script through a web server. Is that what you're
getting at? You want your web server to run a C++ program and serve the
output to a web browser? If so, then it's just an issue of configuring your
web server. But that's off-topic here.
I've written an application in perl, but I want to port it to
C++ or similar, using a complied executable instead of a
Perl script.

FYI, if you're processing GET/POST requests, you might find this C++ CGI
library helpful:

http://www.cgicc.org/

You'll probably want to use some other non-standard library for accessing
your database.

In any case, it sounds like another newsgroup would be more helpful to you.
comp.infosystems.www.authoring.cgi, maybe.
 
A

Arthur J. O'Dwyer

If that's all I wanted, I could just write the HTML file myself.

In Perl, for instance, I can write a script that outputs HTML.
If I run the script

via a CGI-BIN server or similar, I presume?
it outputs the text to the screen. But I
can point Internet Explorer at the script, and it displays
a web page. This is dynamically generated, it varies according
to data read from a database.

Depends on what support your host has for CGI. Geocities, for example,
doesn't have any. Point IE at a Perl script hosted there, and you
get a screenful of line noise. (Perl source, that is.) The same thing
happens if I point IE at a Perl script on my hard disk, although if
you have it configured differently, I've no doubt you could get a "CGI
server" on your own machine. I'd kind of like that. :)
I've written an application in perl, but I want to port it to
C++ or similar, using a complied executable instead of a
Perl script.

Look up the Perl equivalent of 'system()'. Then compile your C++
program to an executable (for whatever OS is running on your host
machine), and exec that program via a Perl script. Completely
untested and OT stuff follows:

% cat hello.cc

#include <iostream>
int main()
{ std::cout << "Hello world!" << std::endl; return 0; }

% cat hello.cgi
#!/usr/bin/perl

print "Content-type: text/html\n\n";
print `./hello`; ## Note the backquotes!

% g++ -o hello hello.cc
% chmod 755 hello.cgi

HTH,
-Arthur
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,138
Messages
2,570,805
Members
47,349
Latest member
jojonoy597

Latest Threads

Top