分页: 1 / 1

Re: c++ 练习源码,均测试通过 CGI

发表于 : 2024-10-29 15:25
rungod

代码: 全选

#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
 
   cout << "Content-type:text/html\n\n";
   cout << "<html>\n";
   cout << "<head>\n";
   cout << "<title>Hello World the first CGI</title>\n";
   cout << "</head>\n";
   cout << "<body>\n";
   cout << "<h2>Hello World! the first CGI program</h2>\n";
   cout << "</body>\n";
   

    return 0;
}
代码很简单,却踏了新手两个经典坑:
1.在windows客户端编译好的二进制不能直接上传到linux服务端;
2.cout << "Content-type:text/html\n\n";这句一定是两个“\n”,否则报500错误,这个问题很隐蔽。

c++ 练习源码,均测试通过 终端基本输入输出求平均数

发表于 : 2024-10-29 10:50
rungod

代码: 全选

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

int main(){
	int total;
	int gradecouter;
	int grade;
	int average;
	total=0;
	gradecouter=1;
	while (gradecouter<=10){
		cout<<"input number please:";
		cin>>grade;
		total=total+grade;
		gradecouter=gradecouter+1;
		
	}
	average=total/10;
	cout<<"Class average is"<<average<<endl;
	return 0;
}