#ifndef MYHEAD_H #define MYHEAD_H ……//头文件中的内容 #endif
#ifndef MYHEAD_H #define MYHEAD_H #include "myhead.h" ...... #endif
int main()
{
#ifdef DEBUG
cout<<"Beginning execution of main()\n";
#endif
string word;
vector<string> text;
while(cin>>word)
{
#ifdef DEBUG
cout<<"word read:"<<word<<"\n";
#endif
text.push_back(word);
}
//..... }
#ifndef MYHEAD_H
#define MYHEAD_H
#ifdef __cplusplus
extern "C" {
#endif
int DMpostprocessing();
#ifdef __cplusplus
}
#endif
#endif
if(element_count==0) cerr<<"Error:"<<__FILE__ <<":line"<<__LINE__ <<"element_count must be non-zero.\n";
assert(filename!=0);
#include <fstream>
//为了打开一个输出文件,先声明一个ofstream类型的对象:
ofstream outfile("name-of-file");
//为了测试是否已经成功打开了一个文件,如下判断:
//如文件不能打开值为false
if(!outfile)
cerr<<"Sorry! We were unable to open the file!\n";
//为了打开一个输入文件,先声明一个ifstream类型的对象:
ifstream infile("name of file");
if(!infile)
cerr<<"Sorry! We were unable to open the file!\n";
一个简单程序:
#include <iostream>
#include <fstream>
#include <string>
int main()
{
ofstream outfile("out_file");
ifstream infile("in_file");
if(!infile){
cerr<<"error:unable to open input file!\n";
return -1;
}
if(!outfile) {
cerr<<"error:unable to open output file!\n";
return -2;
}
string word;
while (infile>>word)
outfile<<word<<' ';
return 0;
}
//shape.h
#include "math.h"//在计算三角形面积时要用到正弦函数
const double pi=3.14159265358;//常量定义
struct circle//类型声明
{
double r;
};
struct square
{
double a;
};
struct rectangle
{
double a,b;
};
struct triangle
{
double a,b,c,alpha,beta,gamma;
};
double perimeter_of_circle(double r)//函数定义
{
return 2*pi*r;
}
double area_of_circle(double r)
{
return pi*r*r;
}
double perimeter_of_square(double a)
{
return 4*a;
}
double area_of_square(double a)
{
return a*a;
}
double perimeter_of_rectangle(double a,double b)
{
return 2*(a+b);
}
double area_of_rectangle(double a,double b)
{
return a*b;
}
double perimeter_of_triangle(double a,double b,double c)
{
return a+b+c;
}
double area_of_triangle(double a,double b,double gamma)
{
return sin(gamma/180*pi)*a*b/2;
}
//main.cpp
#include "iostream.h"
#include "shape.h"//包含我们编写好的shape.h
int main()
{
circle c={2};
square s={1};
rectangle r={2,3};
triangle t={3,4,5,36.86989,53.13011,90};
cout <<"Perimeter of circle " <<perimeter_of_circle(c.r) <<endl;
cout <<"Area of square " <<area_of_square(s.a) <<endl;
cout <<"Perimeter of rectangle " <<perimeter_of_rectangle(r.a,r.b) <<endl;
cout <<"Area of triangle " <<area_of_triangle(t.b,t.c,t.alpha) <<endl;
return 0;
}
Perimeter of circle 12.5664 Area of square 1 Perimeter of rectangle 10 Area of triangle 6
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有