C++ output with webpages
Is it possible to have a c++ program like this...
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}
And have it's output on a webpage like this...
<开发者_开发知识库;html>
<head>
<title>C++</title>
</head>
<body>
<div src = "cpp.exe"></div>
</body>
</html>
Not in the HTML per se, no. But if your server supports it (e.g., Apache), you can use a server-side include to execute a program and include the output on the web page.
Your HTML page would look like this:
<html>
<head>
<title>C++</title>
</head>
<body>
<div><!--#exec cmd="cpp.exe" --></div>
</body>
</html>
It isn't a very good approach because there are better ways to produce dynamic content. But if you really, really need to do it this way, that's how...
Not in this way, but you can use C++ as a server side language (pretty much like many others around). This library seems to be interesting: Tntnet. Take a look a this example.
Jeff is right.
You can also use a library like CPPCMS that allow you to do almost the same thing that what you need :
void my_hello_world::main()
{
cout<<"<html>\n"
"<body>\n"
" <h1>Hello World</h1>\n"
"</body>\n"
"</html>\n";
}
Read this tutorial for details : http://art-blog.no-ip.info/wikipp/en/page/tut_hello_world_code
However just make sure that C++ is really what you want to use. As explained in the rationale, the only reason you'd like to use it is in cases you need high performance for your web app. See : http://art-blog.no-ip.info/wikipp/en/page/rationale
With little modifications to the html, yes, using SSI.
You basically have two possibilities. SSI is built into a number of web servers such as Apache. Alternatively, especially for some older web servers that have less capability built in, or if you want some extra features (e.g., running the program on a separate machine from the web server) you might consider using something like FastCGI.
精彩评论