上一页 1 ··· 26 27 28 29 30 31 32 33 34 ··· 49 下一页
摘要: //26 前置跟后置自加/*#include <iostream>using namespace std;class A{public: A(int n){ rx=n;} friend ostream&operator<<(ostream&s, const A&c){ s<<c.rx<<endl; return s; } friend istream&operator>>(istream&s, A&c) { s>>c.rx; return s; } //前置运算符 int o 阅读全文
posted @ 2012-09-24 22:30 简单--生活 阅读(180) 评论(0) 推荐(0) 编辑
摘要: // 25重载自加运算符的执行次序/*#include <iostream>using namespace std;class A{public: A(int n){ rx=n;} friend ostream&operator<<(ostream&s, const A&c){ s<<c.rx<<endl; return s; } //前置运算符 int operator++(){ cout<<"++i"<<endl; rx++; return rx; } //后置自加 int 阅读全文
posted @ 2012-09-24 22:29 简单--生活 阅读(251) 评论(0) 推荐(0) 编辑
摘要: // 23重载输出运算符/*#include <iostream>using namespace std;class A{public: A(int x, int y){ rx = x; ry = y; }//private: int rx; int ry;};ostream&operator<<(ostream&s, const A&c){ s<<c.rx<<" "; s<<c.ry<<endl; return s;};int main(){ A a(3,4), b(5,6); 阅读全文
posted @ 2012-09-24 22:27 简单--生活 阅读(185) 评论(0) 推荐(0) 编辑
摘要: // 24友无的方式重载输出运算符//本节的开头首先讲一下运算符的知道,<<是按位左移运算符,但是当该符号与流对象,比如说cout连用地就变成了输出运算符,或者叫提取运算符//注意它们的区别,接位左移动算符是用来执行位移操作的,比如说//int num=1;//num<<1;//按位左移运算符(<<)将运算符左边的运算对像num向左移动运算符右侧指定的位数1,然后在低部补0//了解了它们的区另以后,接下来有个问题,按位左移运算符和输出运算符这两个符号是一样的,编辑器是如何来区分它们的,为了解释这个问题,我们需要返回到上一节的代码中/*#include < 阅读全文
posted @ 2012-09-24 22:27 简单--生活 阅读(440) 评论(0) 推荐(0) 编辑
摘要: // 21string数组与函数/*#include <iostream>#include <string>//假如要传递多个字符串,那么可以声明一个string对像数组,然后将数组传递到函数中using namespace std;void show(const string str[], int l);int main(){ const int l = 5; string st[l]; for(int i=0; i<l; i++) { cout<<i<<"请输入:"<<endl; cin>>s 阅读全文
posted @ 2012-09-24 22:26 简单--生活 阅读(221) 评论(0) 推荐(0) 编辑
摘要: //22流的简介/*"流"从字面上理解是流动的意思,书面上的解释是物质从一处往另一处流动的过程C++的输入和输出遵循了这一概念,C++的输出是将一个对像的状态下换成一个字符序列,车出到指定的地方cout<<"hello world";双引号中的hello word是所有输出的对像,C++的重载按位左移运算符<<将对像转换成一个向左移动的字符序列,cout则表示将其输出在计算机外部设备管理中,如显示器的屏幕上C++的重载按位右移运算符>>表示从指定地方按照向右移动的顺序接受字符序列,然后将其转换为对像的数据成员的格式,c 阅读全文
posted @ 2012-09-24 22:26 简单--生活 阅读(260) 评论(0) 推荐(0) 编辑
摘要: // 20结构体与string//string是一个类,在C++中类与结构体区另不大,因此string类与结构体的区别也不大,既然string类结构体的区别不大,那么我们可以把一个结构传递给函数并返回结构体,我们自然也可以把string对像传递给函数或者返回一个string对像/*#include <iostream>#include <string>using namespace std;const string& show(const string &p){ cout<<p<<endl; return p;}int main( 阅读全文
posted @ 2012-09-24 22:25 简单--生活 阅读(261) 评论(0) 推荐(0) 编辑
摘要: //19 结构体与函数//由于结构可以看作一个数据类型并且可以赋值,因为我们可以将结构传递到函数中,或者在函数中返回一个结构//按值返回我们知道需要复制返回的结构,结构体可以容纳不同的类型的变量,相应产生的问题是复制数据也很多,假如我们不想复制数据,那么就要按地址返回/*#include <iostream>using namespace std;struct time{ int hour; int minute;};const int perhour = 60; //定义分钟数//time sum(time t1, time t2);time *sum(time t1, time 阅读全文
posted @ 2012-09-24 22:24 简单--生活 阅读(250) 评论(0) 推荐(0) 编辑
摘要: //17结构体与类的区别//我们知道结构体是C时代的产物,到了C++之后结构体有了很大的变化,可以增加函数,可以设置成员的公有,私有和保护属性,可以从别的类继承,也可以被别的类继承,可以有虚函数据//唯一与类不同之处的地方是,结构体的成员默认是public,而类的成员默认是private./*#include <iostream>#include <string>using namespace std;//由于结构体的这种默认公有属性,我们一般用来保存多个数据类型,比如说//我们要保存一个人的姓名,性别,年龄,身高和体重struct A{//public: int ge 阅读全文
posted @ 2012-09-24 22:23 简单--生活 阅读(266) 评论(0) 推荐(0) 编辑
摘要: //18结构体的赋值//结构既然是一种数据类型,那么我们就可以象变量那样进行赋值操作,不过前提是必须两个结构都是同类型/*#include <iostream>using namespace std;struct people{ double weight; double tall;};int main(){ people Mick = {111.1, 99.9}; people Jack = {222.3,55.4}; cout<<Mick.tall<<" "<<Mick.weight<<endl; cout&l 阅读全文
posted @ 2012-09-24 22:23 简单--生活 阅读(173) 评论(0) 推荐(0) 编辑
上一页 1 ··· 26 27 28 29 30 31 32 33 34 ··· 49 下一页
简单--生活(CSDN)