
c++
文章平均质量分 60
OPK625153475
这个作者很懒,什么都没留下…
展开
-
数据库与C++的七个函数
1 、打开数据库: 说明:打开一个数据库,文件名不一定要存在,如果此文件不存在, sqlite 会自动创建。第一个参数指文件名,第二个参数则是定义的 sqlite3 ** 结构体指针(关键数据结构),这个结构底层细节如何,您不用管它。 int sqlite3_open( const char *filename, /* Database filename (UTF-8) */原创 2013-06-02 15:51:52 · 3290 阅读 · 0 评论 -
类的私有继承
#include using namespace std;class B{public: void getx(int n) {x=n;} void disp() {cout<<x<<endl;}private: int x;};class D:private B{public: void getxy(int n,int m) { getx(n); y=m;原创 2012-07-25 12:00:41 · 746 阅读 · 0 评论 -
对象与常对象的区别
#include using namespace std;class Date{public: Date(int y,int m,int d); void showDate(); void setDate(int y,int m,int d); void showDate() const; //void setDate1(int y,int m,intd) cons原创 2012-07-25 12:16:39 · 841 阅读 · 0 评论 -
常数据成员的初始化
#include using namespace std;class Date{public: Date(int y,int m,int d); void showDate(); void setDate(int y,int m,int d);private: const int year; const int month; const int day;原创 2012-07-24 16:01:45 · 4978 阅读 · 0 评论 -
c++输入输出 流的应用
#include #include #include using namespace std;class Copy_file{public: Copy_file(); ~Copy_file(); void Copy_files(); void in_file(); void out_file();protected:private: fstr原创 2012-08-11 00:31:47 · 825 阅读 · 0 评论 -
文件输入输出的两种方法(常用第一种)
#include#include#includeusing namespace std;int main(){ ofstream fout1("test2.dat"); ifstream fin1("test2.dat"); if(!fout1) { cout<<"can`topen fill .\n "; exit(1); //return原创 2012-08-10 22:52:15 · 687 阅读 · 0 评论 -
派生类构造函数与析构函数的构造规则
1.派生类的构造函数可以不显示式的写出基类的构造函数。例如:Third() {e=0;}此时,系统自动调用基类的无参构造函数(没有,则为默认的构造函数)。也可显示式的指出调用基类的哪一个构造函数。例如:Third(int x,int y,int z):Second(x,y) { e=z; }2.要调用的基类构造函数的参数可在派生类的构造函数中明确给出原创 2012-07-27 00:55:14 · 1135 阅读 · 0 评论 -
C++文件的打开与关闭
文件流对象.open(文件名,使用方式) 文件名如果不使用绝对路径,则文件名为当前目录下的文件 文件的使用方式方式功能ios::in已输入方式打开文件ios::out以输原创 2012-08-10 00:39:51 · 1923 阅读 · 0 评论 -
派生类的构造函数与析构函数
当基类构造函数没有参数或没有定义构造函数时,派生类可以不向基类传递参数,甚至可以不定义构造函数。当基类含有带参数的构造函数时,派生类必须定义构造函数,提供把参数传递给基类构造函数的途径。如果派生类的基类也是派生类,每个派生类子须负责其直接基类成员的初始化。#includeusing namespace std;class B{public: B(int n) {cout原创 2012-07-26 23:01:30 · 689 阅读 · 0 评论 -
文件的输出与输入两种方法(常用第一种)
#include#include#includeusing namespace std;int main(){ ofstream fout1("test2.dat"); ifstream fin1("test2.dat"); if(!fout1) { cout<<"can`topen fill .\n "; exit(1); //return原创 2012-08-10 22:32:23 · 826 阅读 · 0 评论 -
基类成员在派生类中的调整
//访问声明,只能把基类的公有成员调整为私有派生类的公有成员,保护成员也如此。则,私有成员不能#includeusing namespace std;class A{public: A(int x1) {x=x1;} void show() { cout<<"x="<<x <<endl; } protected: int y;pri原创 2012-07-28 00:19:24 · 1510 阅读 · 0 评论 -
用vector对象方法,给n个元素,每个元素值为var
方法一:vector ivec(10,42);方法二:vector ivec(10);for (ix=0;ix<10;++ix){ ivec[ix]=42;}方法三:ector ivec(10)for(vector::iterator iter=ivec.begin();iter!=ivec.end();++iter) *iter=42;原创 2012-08-18 12:09:57 · 1296 阅读 · 0 评论 -
VC++6.0出现系统不支持的错误怎么办
如出现近似问题fatal error C1001: INTERNAL COMPILER ERROR (compiler file 'msc1.cpp', line 1786) Please choose the Technical Support command on the Visual C++ Help menu, or ope原创 2012-08-01 23:02:17 · 2105 阅读 · 0 评论 -
何时需要虚函数(虚析构造函数的好处)
1.当能通过基类指针撤销派生类对象时;2,。带有多态性质的基类,如果类中有任何虚函数,那就应该将该类析构函数定义为虚函数。3.如果类的设计不是作为基类来使用,或不具备多态性,则不用声明为虚函数撤销派生类的无名对象#includeusing namespace std;class Base{public: virtual ~Base() { cout<<"B原创 2012-07-31 12:24:09 · 794 阅读 · 0 评论 -
运算符的重载及调用方式
定义重载运算符函数:opereator@(),其中@表示运算符号#includeusing namespace std;class Complex{public: double real; double imag; Complex(double r=0,double i=01) { real=r; imag=i; }};Complex ope原创 2012-08-01 12:25:31 · 2028 阅读 · 0 评论 -
虚函数与重载函数的关系
1.普通的函数重载是,函数的参数或参数类型必须先有所不同,返回类型也可不同。2.虚函数重载时,要求函数名,返回类型,参数个数,参数类型,顺序都要与基类函数原型完全相同 a..当返回类型不相同,其他完全相同,则报错 b.函数名相同,而参数个数,参数类型,顺序不同,系统视为普通重载,失去虚函数特性#includeusing namespace std;c原创 2012-07-31 12:52:43 · 3295 阅读 · 0 评论 -
虚函数的好处
#includeusing namespace std;class Base{public: Base(int y1,int x1) {y=y1; x=x1; } virtual void show() { cout<<"Base............"<<endl; cout<<"y="<<y<<" x="<<x; }p原创 2012-07-30 23:53:10 · 1032 阅读 · 0 评论 -
人,学生,职工虚基类的例子
#include#includeusing namespace std;class Person{public: Person(string name1,char sex1,int age1) { name=name1; sex=sex1; age=age1; } void print() { cout<<"姓名:"<<name<<end原创 2012-07-30 23:07:17 · 2700 阅读 · 0 评论 -
虚基类声明,初始化及调用顺序
1.如果虚基类中定义有带参数的构造函数,并且没有默认定义构造函数,则整个继承结构中,所有直接或间接的派生类必须在构造函数的成员初始化列表中列出虚基类构造函数的调用。2.建立对象时,如果这个对象中含有从基类继承来的成员,则虚基类的成员有最远派生类的构造函数通过调用虚基类的构造函数进行初始化的,该派生类的其他基类对虚基类构造函数的调用都自动忽略。3.如果同一层次中同时有虚基类和非虚基类,则先调原创 2012-07-29 00:19:50 · 6477 阅读 · 1 评论 -
涌流成员函数进行输入输出格式控制
1。设置状态标志位的流成员函数 setf()一般格式: long ios::setf(long flags);调用格式: 流对象.setf(ios::状态标志)状态的作用如下:ios::skipws //跳过输入中的空白符,用于输出ios::left //输出数据在本域宽范围内左对齐,用于输出ios::right //输出数据在本域宽范围内右原创 2012-08-09 23:05:51 · 842 阅读 · 0 评论 -
类的保护继承
#includeusing namespace std;class B{public: int z; void getx(int i) {x=i;} int putx() {return x;}private: int x;protected: int y;};class C:protected B{public: int p; void getall(int a原创 2012-07-25 22:33:38 · 510 阅读 · 0 评论 -
函数模板
template返回类型 函数名(模板形参表){ 函数体}或者template返回类型 函数名(模板形参表){ 函数体}建议用第一种模型#includeusing namespace std;template//int i; //错误的,在template语句与函数模块定义之间不允许插入原创 2012-08-05 12:53:47 · 436 阅读 · 0 评论 -
重载的应用
#includeusing namespace std;class Triangle{public: Triangle(int a,int b) { height=a; base=b; } friend ostream& operator<<(ostream& output,Triangle& T);private: int height,base;原创 2012-08-04 23:57:52 · 570 阅读 · 0 评论 -
通过类型转换函数进行类型转换
#includeusing namespace std;class Complex{public: Complex(){} Complex(int r,int i) { real=r; imag=i; cout<<"constructing------------\n"; } Complex(int i)//把int型转换为类对象成原创 2012-08-04 23:32:32 · 614 阅读 · 0 评论 -
“[]”运算符的重载
#includeusing namespace std;class Vector{public: Vector(int a1,int a2,int a3,int a4) { v[0]=a1; v[1]=a2; v[2]=a3; v[3]=a4; } int& operator[](int vi);private: int v[4];原创 2012-08-03 23:28:36 · 435 阅读 · 0 评论 -
重载插入运算表福“<<”
#includeusing namespace std;class Complex{public: Complex(double r=0.0,double i=0.0); friend Complex operator+(Complex& a,Complex& b); friend ostream& operator<<(ostream&,Complex&);priva原创 2012-08-04 22:00:12 · 736 阅读 · 0 评论 -
前缀方式与后缀方式的识别
operator++();//前缀方式operator++(int);//后缀方式(出此之外,没任何作用)原创 2012-08-02 23:54:15 · 761 阅读 · 0 评论 -
使用深拷贝解决指针悬挂问题(“=”运算符重载)
#includeusing namespace std;class STRING{public: STRING(char *s) { cout<<"constructing called."<<endl; ptr=new char[strlen(s)+1]; strcpy(ptr,s); } ~STRING() { cout<<"des原创 2012-08-02 22:26:58 · 1860 阅读 · 0 评论 -
内嵌子对象时派生类构造函数与析构函数的调用顺序
调用顺序1.调用基类的构造函数,对基类数据成员初始化。2,调用子对象构造函数,对子对象数据成员初始化;3.调用派生类的构造函数,对派生类数据成员初始化。#includeusing namespace std;class Base{public: Base(int n) { i=n; cout<<"constructing Base class"<<原创 2012-07-26 23:38:16 · 3360 阅读 · 0 评论 -
c/c++库
http://www.cplusplus.com/reference/algorithm转载 2012-07-24 14:51:09 · 802 阅读 · 0 评论 -
指针与对象,指针与对象数组的联系与区别
#include using namespace std;class Recta{public: Recta(int len=10,int wid=10) { length=len; width=wid; } int getArea() { return (length*width); } void disp() { cou原创 2012-07-24 14:56:15 · 494 阅读 · 0 评论 -
适用于定义的操纵符进行输入输出格式控制
ws //用于输入时跳过开头的空白符,用于输入ends //插入一个空字符null,通常用来结束一个字符串,用于输出flush //刷新一个输出流,用于输出setbase(n) //设置整数的基数为n,默认为十进制setfill(c) //设置填充符,默认为空格,用于输出setprecision(n) //设置实数精度为n,当为fixed或scientific形式时,n为小数原创 2012-08-09 23:52:53 · 1226 阅读 · 0 评论 -
cin与cin.getline()的区别
1.cin能读取C++标准类型的各类数据(如果经过重载,还可以用于输入自定义的类型数据),而cin.getline()只能用于输入字符类型数据2.使用cin>>读取数据以空白字符作为终止字符,cin.getline()可连续读取一系列字符,可以包括空格。原创 2012-08-08 22:34:12 · 940 阅读 · 0 评论 -
析构函数的使用与调用
#include #include using namespace std;class Student{public: Student(char *name1,char *stu_no1,float score1); ~Student(); void show(); void show_count_sum_ave();private: char *name;原创 2012-07-24 15:40:54 · 548 阅读 · 0 评论 -
类的公有继承
#includeusing namespace std;class B{public: void getab(int a1,int b1) { a=a1; b=b1; } void dispab() { cout<<"a="<<a<<endl; cout<<"b="<<b<<endl; }private: int a;protected:原创 2012-07-25 12:52:30 · 1099 阅读 · 0 评论 -
类的继承
//人类学生类#include #include //#include using namespace std; class Person{ public: Person(string name1,int age){ //name=new string; this->name=name1; this->age=age; } virtual void sh原创 2012-07-25 12:08:05 · 538 阅读 · 1 评论 -
对象作形参 的几种形式
#include using namespace std;class A{public:A(int n){i=n;}void set(int n){i=n;}int get(){return i;}private:int i;};void sqr(A ob) //传值调用{ob.set(ob.get()*ob.get());cout<原创 2012-07-24 15:25:05 · 989 阅读 · 0 评论 -
抽象类的作用
//抽象类//如果一个类中至少有一个纯虚函数,则为抽象类。其目的是用它作为基类建立派生类。//1.由于抽象类中至少有一个没有定义功能的纯虚函数,因此,抽象类只能作为其他类的基类来使用,// 不能建立抽象类对象。// 2.不可从具体类派生出抽象类,(没有纯虚函数的普通类)//3.抽象类不能用做函数的参数类型,返回类型或显示转换的类型。//4.可以声明指向抽象类的指针或引用(抽原创 2012-08-01 20:06:05 · 4636 阅读 · 0 评论