?C++ Server Pages?

{NcsO}ReichstaG

[H]ard|Gawd
Joined
Aug 13, 2004
Messages
1,768
Hello,
I am developing a website, and I was thinking of using C++. I know C++ better than I do PHP or other languages. One interesting solution I found for using C++ for web development were the C++ Server Pages by Micronovae.
http://www.micronovae.com/default_csp.html
Has anyone ever tried that before? Also, C++ would be almost useless if I could not have it interact with MySQL database. Are there libraries out there that allow me to use C++ with MySQL?
Or is C++ not practical for web development?

{Since I am not a C++ expert, I can't write my own libraries}
 
C++ is not practical for web development. I don't think I have ever seen it used like that. Since you already know one language, it shouldn't be too terribly difficult to pick up another like PHP. It will be much easier in the end to learn how to do what you want to do using the right tool for the job than it will be using the wrong tool for the job. In other words, if you don't know how to use a screwdriver then driving screws with a hammer will be much more difficult than just learning how to use a screwdriver.
 
i must ask why do you think it is not practical? because you have to compile it instead of having an interpreted language?

i personally prefer PHP because i know it well but if i were a C++ guru, i'm sure i would use that instead.

it is trivial to make a c++ program output for the web
Code:
#include <cstddef>
#include <iostream>

using namespace std;

void print_header();

int main() {
    print_header();

    cout << "Hello web!" << endl;
}

void print_header() {
    cout << "Content-type: text/html\n\n";
}
once you compile this, you would need to put it in your cgi-bin and name it whatever.cgi

now it is not exactly trivial to use variables passed via get and post, but certianly doable. i believe you need to get the environmental variable QUERY_STRING then splitting it by & and splitting each of those by =

PHP is "easier" to use because a great deal of this kind of stuff is done automatically for you. of course, you can do basically anything at all with c++ whereas PHP may not be suited for every application. i'm not saying either is better, i say use whatever you're comfortable with.

as far as mysql, yes you can use it. the actual API is apparantly in C but i found this link on mysql's site:
http://tangentsoft.net/mysql++/ . presumably you need the C API in order to use the wrapper on that link. from what i gather, it's included if you download the source files. now understand, i'm no c++ expert and i haven't used mysql with anything other than PHP so i may be wrong here, i'm just interpreting some stuff.
 
I have heard of using C++ for CGI purposes, but have never met anyone who actually does it. All my colleagues and I use Perl for CGI scripts, it's a lot easier to us (though we're pretty experienced in C and C++).

tim_m's link is the only library I know of that you can use to interact with mySQL from within C++ - it was originally developed by mySQL, but maintenance was handed off.
 
{NcsO}ReichstaG said:
Thanks for your comments. I guess C++ is not too practical for web development....

I know a guy who uses x86 assembler and linux syscalls. :rolleyes:
Once you get your foundation done (handling input and output, plus the MySQL connection), it shouldn't be too bad. (I'd still use PHP, though. Many useful things are done for you, or simplified.)
 
I wrote a program in straight C for an embedded system; it generated statistics for a process (FAH). If you'd like source, I can mail it to you, but it's pretty messy.

It actually doesn't do the parsing of QUERY_STRING, but I later converted to perl, and here's the code for that:
Code:
# GET method
foreach $param (split(/\&/, $ENV{"QUERY_STRING"}))
 {
  ($name, $val) = split(/\=/, $param);
  $val =~ s/\%([0-9A-F]{2})/pack('H2', $1)/eg;  # Change % escapes into characters.
  $arg{"$name"} = $val;
#  print "$name = $val<br>\n";
 }
# POST method
$length = $ENV{'CONTENT_LENGTH'};
read(STDIN, $data, $length);
foreach $chunk (split(/\&/, $data))
 {
  $chunk =~ s/\%([0-9A-F]{2})/pack('H2', $1)/eg;  # Change % escapes into characters.
  $chunk =~ s/\+/\ /g;
  ($name, $val) = split(/\=/, $chunk);
  $args{"$name"} = $val;
#   print "$name = $val<br>\n";  # Debugging purposes
 }
Obviously, don't use both. Then you can access parameters like key=value as such:
$arg{"key"} == value;
If you need more help getting started, feel free to ask or PM.

 
HHunt said:
I know a guy who uses x86 assembler and linux syscalls. :rolleyes:
Once you get your foundation done (handling input and output, plus the MySQL connection), it shouldn't be too bad. (I'd still use PHP, though. Many useful things are done for you, or simplified.)

Ha, I bet his webpages run really really fast.
 
Thanks for your input. I guess I will just stick to the appropriate languages like PHP...
Can Java 2 be used for web authoring? Not terms of putting visuals like games on the website, but for doing things normally done in PHP? Like having an applet that takes a person's registration info, checks it, and submits it into a MySQL db?
 
you can write ASP.net in C++.net or any of the other .net languages. I'd suggest looking at C#
 
This question is not related to web authoring. However, I was wondering what is really required to take C++ on step farther. The basic C++ that I studied is about loops, variables, variable types, arrays, pointers, functions, OOP, and stuff like this. However, what is required to write "real world" programs that can add themselves to the registry and so on. I don't think such features are part of the C++ standard library. Is MFC required for that or what...?
 
{NcsO}ReichstaG said:
This question is not related to web authoring. However, I was wondering what is really required to take C++ on step farther. The basic C++ that I studied is about loops, variables, variable types, arrays, pointers, functions, OOP, and stuff like this. However, what is required to write "real world" programs that can add themselves to the registry and so on. I don't think such features are part of the C++ standard library. Is MFC required for that or what...?
Learning appropriate APIs or packages (MFC is an option). This is only debateably taking C++ a step further, as in principle it's no different from including iostream.h. Granted the level of complexity is higher but you're not unlocking new features of the language proper.
 
Is MFC still worth learning or is MS going to drop the support for it? Also, what appropriate APIs do you have in mind?
 
{NcsO}ReichstaG said:
Hello,
I am developing a website, and I was thinking of using C++. I know C++ better than I do PHP or other languages. One interesting solution I found for using C++ for web development were the C++ Server Pages by Micronovae.
http://www.micronovae.com/default_csp.html
Has anyone ever tried that before? Also, C++ would be almost useless if I could not have it interact with MySQL database. Are there libraries out there that allow me to use C++ with MySQL?
Or is C++ not practical for web development?

{Since I am not a C++ expert, I can't write my own libraries}

Never tried CSP. That may be interesting having a c++ interpreter like that. I'll have to try that out.

As for writing and building your own app, A while ago, I searched for c++ libraries, and only found a few sets. However I didn't feel like learning how they worked and they didn't impress me anwyay so I wrote a few simple (nothing special) functions to get variables and values from query strings and encode and decode data etc.

Basically, it offered me no benefit over php/perl/python etc. It was just something to play with, b ut CSP may be different.
 
PHP is a good web development language and isn't too hard to learn. ASP is also another language that is really helpful and can be learned in no time.

www.w3schools.com
 
I tried the c++ server pages.

here's a super simple example.

Code:
<%!
char* test = "http://www.google.com/";
%>
<html>
<head>
<title>test</title>
</head>
<body>
<div><a href="<%= test %>"><%= test %></a></div>
</body>
</html>

I could not make much more of an example as just putting in c++ code and going at it didn't work. Looks like you'd still have to learn some specifics, which the time could be better spent on learning php better.

It does appear that you can do *something* like this though, which is cool.

Code:
<%
for (int i = 0; i < 1000; ++i) {
%>
<div> <%= i %> </div>
<%
}
%>
 
MFC is still supported. (In fact, the team is hiring.)

ISAPI is faster than CGI if you want to write C++ for your extensions.
 
Back
Top