Thread: Can C++ be used as a CGI?

  1. #1
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434

    Question Can C++ be used as a CGI?

    I was just reading an HTML tutorial and when the topic of languages that could be used for CGI it mentioned C++. I was just wondering if this information was accurate. If it is possible how do i go about doing it? Thanks guys!

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    1) You go to this webiste:

    www.google.com

    2) That site will present you with a text box that has a button next to it with the incantation: "Search". Type "cgi c++" into the textbox, hold your breath, and click on the Search button and see what wonders present themselves.

  3. #3
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    First of all, watch how you talk to people. Your no better than i am, perhaps at C++ and programming but that doesnt make you a better person than i am so dont talk down to me and be a smart mouth, its people like you who drive me away from these forums. It had gotten better, people had gotten more friendly, than you start talking down to me and i remember others who have done the same. Im gonna ignore that fact this time (unlike the last time someone pulled something like this with me).

    Secondly, i tried that and got no definitive answers. It looks like i may be able to but i didnt get any sites that said: "How to use C++ as a CGI" i got some stuff similar with things about MySQL (which i only vaguely know about). So if someone could kindly help me out id appreciate it.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Yes, C++ can be used for CGI scripts. It's not very common - Perl and PHP are by far the most common, but it's possible. You just need a server that allows you to use C++ - though I can't name any specifics off the top of my head - But I'd be surprized if the hugely popular Apache couldn't do this for you.

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    My magic must be more powerful than yours. Try clicking your heels three times and chanting: "there's no place like home, there's no place like home." After that use the magic number '7' to count down the page to the 7th link displayed and let your gaze settle on the inscription: "cgi and c++". Beware the black magic contained therein.

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Your attitude is trying my patience, 7stud, cut it out. The original post is pretty mild compared to a lot of others.

  7. #7
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    Thanks sean, i dont have a server but you can download that apache to simulate a server on your home computer right? I have been teaching myself HTML from online stuff and now i want to learn how to script some CGI stuff.

    I know that his original post was mild but its things like that that start arguments and once again, i dont think anyone, no matter how rich, poor, good-at-programming, bad-at-programming, has the right to talk down to people, especially for asking a simple yes or no question.

    Thanks again sean, as usual you have been a great help. Now if i wanted to start learning PERL/PHP do i need anything special other than that apache? Which would you reccommend learning perl or PHP? Thanks!

  8. #8
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Well a server refers to several things. It can refer to any computer receiving and responding to a request over a network. It can refer to the program running on that computer that handles the request. And it can refer to a computer that was specially designed to be used as a web server. Take your pick...

    All you need for Perl is an interpreter to run the scripts and a good tutorial or book.

  9. #9
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    Ok ill keep my eye out, would the apache on a home computer suffice for a server just for learning purposes? I may be getting a server type thing from my dad who just baught a new one then sold his company. He used it for networking i think. Hopefully ill be able to use it. Ok so i need an interpreter, a server, and just a good tutorial / book. Thanks again Sean!

  10. #10
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    I don't see why it wouldn't - but I've never actually used Apache for myself - just researched it a bit.

  11. #11
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Junior89, just so you know, although you can use C++ for CGI, most people would say it's not really the best language for the task. Typically Python or PERL are more suited. However, if you want to use C++, go for it. Just be aware there are other options and C++ is not always the best tool for a given task.
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  12. #12
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    275
    Junior89, you can use C++ for CGI. But i don't recommend you to use C++ CGI programs since PHP provides you more powerfull and easy programming unless you have a good reason for using CGI!
    Once I have to write CGI program in C for getting data from a MySQL server because the web server has shell accounts and the PHP file can be read by another users.If i performed my job with PHP, obviously, it would be more easier for me to write the code...

  13. #13
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Despite 7stud's attitude, he was right in his first post. Let me list the first few results when I search for cgi and c++ on Google:
    1) Accessing a MySQL Database from a C++ CGI Program
    Seems to indicate that such a thing exists.
    2) C++ CGI class (1): An introduction
    3) CGI Programs and Scripts - C/C++
    4) C and C++ CGI Programming
    And so on. Good indicator, no?

    There are several downsides to using C++ for CGI.

    One, you have to recompile to deploy on a different system.

    Two, C++ isn't exactly made for outputting large amounts of text, and since it's not very popular in the web, it's also quite hard to find a proper templating engine - in part because template has a wholly different meaning in C++, obscuring search results.

    On the other hand, Google itself uses C++ in the backend. I believe Ebay does, too, and Amazon.

    Three, C++ doesn't have any great facilities for handling the CGI protocol. There are libraries out there, I'm sure, but I'm not sure about their quality.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  14. #14
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    Junior89, you may find <Getting Started with CGI Programming in C> useful. It's up to you to translate this tutorial to a C++ style of programming.

    [Edit: But of course I don't recommend using C++. It's not the easiest language out there, it's not necessarily allowed on your web server, and other languages are better. There's PHP, which is a humongous library of functions in want of a decent programming language, and there's Perl, which I think is a bit better, and of course many others.]
    Last edited by Rashakil Fol; 11-30-2005 at 01:35 PM.

  15. #15
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    It said that it could but most, if not all of them talked about a MySQL database. I dont know what that means. I was hoping just to use C++ for the convience cause i already have it on my computer, but now i know that i need a server i was hoping that just for my learning purposes that i could just put a C++ program into the same folder as the HTML document and tell the HTML document where the program was and hope that that was all that i needed, now i know better. Im going to try to figure out some more stuff with the MySQL, and perhaps PHP and/or PERL if anyone could let me know of a good tutorial and not just tell me to Google it i would appreciate it, also if anyone knows of a good tutorial for C++ as a CGI (other than the one mentioned) i would appreciate it. While Google can show me tutorials i cant say only return the "Good" or well written ones. I will admit that i should have researched the topic more, still that doesnt give someone the right to be rude a simple, friendly "Try Google" Would have sufficed, and it would have taken less effort than being rude; for the people out there who hate to help others out. Thanks everyone who helped me in this matter!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. CGI program help please
    By Lince in forum C Programming
    Replies: 3
    Last Post: 08-01-2007, 01:31 AM
  2. cgi - c++ returns image
    By terracota in forum C++ Programming
    Replies: 1
    Last Post: 08-04-2004, 09:41 PM
  3. testing a cgi script on my computer
    By Bigbio2002 in forum C Programming
    Replies: 1
    Last Post: 12-14-2003, 07:26 PM
  4. CGI Mailing
    By sean in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 04-14-2003, 09:56 PM
  5. Problem with cgi script - can't rename files
    By bjdea1 in forum C Programming
    Replies: 2
    Last Post: 12-12-2001, 04:09 PM