
c++
文章平均质量分 62
「已注销」
这个作者很懒,什么都没留下…
展开
-
argc, argv简单使用
通过一下例子认识一下argc, argv:代码如下:#include using namespace std;int main(int argc, char * argv[]){ char filename[80]; if(argc ==1 || argc > 2) { cout << "input the filename you want to edit: "原创 2014-10-11 14:57:07 · 1008 阅读 · 0 评论 -
c++的矢量类
1.下例中定义了一个矢量类,并对矢量定义了一系列操作:原创 2014-04-22 13:33:06 · 5320 阅读 · 0 评论 -
c++中类的继承
1.从一个类pai原创 2014-05-07 16:35:07 · 481 阅读 · 0 评论 -
c++的构造函数和析构函数
1.构造函数:原创 2014-04-17 21:12:58 · 712 阅读 · 0 评论 -
c++的类作用域
1.在类中定义的名称(如类数据成员名he)原创 2014-04-18 14:08:08 · 816 阅读 · 0 评论 -
使用const保护数组
使用const保护数组的目的是为了确保函数不会修改数组的值。代码实例:void show_arr(const int arr[], int n){ for(int i = 0; i < n; i++ ) { cout << "Property #" << i + 1 <<endl; cout << arr[i] << end原创 2014-03-23 22:59:55 · 544 阅读 · 0 评论 -
处理数组的函数,我们有两种表示方法
①函数原型: int sum_arr(int arr[], int n)#include const int ArSize = 8;int sum_arr(int arr[], int n);using namespace std;int main(){ int arr[ArSize] = {1,2,3,4,5,6,7,8}; cout << "Total is "原创 2014-03-23 22:54:44 · 678 阅读 · 0 评论 -
c++的this指针和对象数组
1.每个成员函数(包括构造函数和析构函数)都有一个原创 2014-04-18 13:20:12 · 860 阅读 · 0 评论 -
c++类的基本概念
1.OOP的重要特性: ●抽象: 将问题的本质特征抽象出来,并根据特征来描述解决方案,抽象是通往用户类型的捷径。 ●封装和数据隐藏 封装:公有接口表示设计的抽象组件,将实现细节放在一起并将它们与抽象分开被成为封装。数据隐藏也是一种封装;将实现的细节隐藏在私有部分中,也是一种封装;将类函数声明和定义放在不同的文件中,也是一种封装。 数原创 2014-04-17 12:08:54 · 3052 阅读 · 0 评论 -
cin作为while循环的条件
使用实例:#include const int MAX = 5;using namespace std;int main(){ float fish[MAX], total = 0; int i = 0; cout << "Please enter the weights of your fish.\n" \n"; cout << "原创 2014-03-21 10:05:29 · 1724 阅读 · 0 评论 -
碰到输入错误时,如何清除错误输入,接受正确输入
实例:#include const int MAX = 5;using namespace std;int main(){ int golf[MAX]; double total = 0; cout << "Please enter your golf scores.\n"; cout << "You must enter 5 rounds.\n";原创 2014-03-21 10:26:49 · 2498 阅读 · 1 评论 -
c++运算符重载和友元函数
1.运算符重载:例如+本来是用于两个整数或者两个浮点数进行相加的,如果我将+重载之后,可将+用于时间对象的相加,比如一个时间对象为1小时50分,一个时间对象为2小时30分,则这样两个时间对象通过重载的+可以直接进行运算得到4小时20分。2.重载+使得+能直接计算时间和的方法:只需要在operator后加上运算符号作为函数名即可:class Time{ private:原创 2014-04-20 21:03:49 · 2360 阅读 · 1 评论 -
c++的引用变量
1.引用:引用是已定义变量的别名。例如:如果原创 2014-04-09 00:25:40 · 671 阅读 · 0 评论 -
c++单独编译和c++的多文件组织结构
1.通常当一个程序代码较多较复杂时,我们会ba原创 2014-04-13 14:23:21 · 13213 阅读 · 3 评论 -
c++程序运行过程
第一步:编辑:编写c++代码,后缀为.cpp,这是源文件第二步:编译:将cpp代码翻译成计算机能够直接识别的二进制的机器语言,包含了翻译后的程序的文件就是程序的目标文件。第三步:链接:将得到的一个或者多个目标文件以及使用的库文件组合在一起,生成可以可以在操作系统直接运行的可执行文件。原创 2014-03-11 13:55:43 · 1079 阅读 · 0 评论 -
c++函数的默认参数
1.默认参数指的是当函数调用时原创 2014-04-09 14:47:00 · 558 阅读 · 0 评论 -
c++函数模板
1.函数模板的定义:原创 2014-04-11 10:38:16 · 723 阅读 · 0 评论 -
类的自动类型转换和强制类型转换
1.可以将类ding原创 2014-04-24 16:13:46 · 765 阅读 · 0 评论 -
构造函数对数据成员进行初始化的方法
1.常规方法:假设定义了如下类:原创 2014-04-25 14:45:25 · 2962 阅读 · 0 评论 -
c++函数重载
1.函数重载(函数多态)指的是可以有多个同名的函数,因此对函数进行重载。函数多态和函数重载指的是同一回事,但是我们通常用函数重载。2.函数重载的条件:要么函数的参数类型不同,要么函数的参数个数不同,或者都不同。3.注意: double cube(double x);double cube(double & x); //这两种是不能重载的long gronk(int n, float m)原创 2014-04-10 18:22:24 · 710 阅读 · 0 评论 -
类的动态内存分配
1.静态类成员原创 2014-04-24 13:39:04 · 696 阅读 · 0 评论 -
c++内联函数
1.内联函数特点:原创 2014-04-08 22:23:47 · 538 阅读 · 0 评论 -
switch的用法
实例:#include using namespace std;void show();void report();void comfort();int main(){ int choice; show(); cin >> choice; while(choice != 5) { switch(choice)原创 2014-03-20 14:00:04 · 716 阅读 · 0 评论 -
用cctype确定字符的类型
cctype使用实例:#include #include using namespace std;int main(){ int digital = 0; int character = 0; int space = 0; int punct = 0; int others = 0; char ch; cout << "Ente原创 2014-03-20 13:25:40 · 651 阅读 · 0 评论 -
菜单类型的重复选择,使用while做到能够一直选择
实例:#include using namespace std;void showMenu();int main(){ char ch; showMenu(); cin >> ch; while(ch != 'q') { if(ch != 'c' && ch != 'p' && ch != 't' && ch != 'g')原创 2014-03-21 16:01:11 · 1772 阅读 · 0 评论 -
循环结构
①for循环: 基本用法: int i;for(i = 0; i < 5; i++){ cout << i << endl;} //i在循环体外部还能使用for(int i = 0; i < 5; i++){ cout << i << endl;} //i只能在循环体内使用 使用实例:#include using namespac原创 2014-03-18 16:56:39 · 466 阅读 · 0 评论 -
二维数组作为参数的函数
假设有如下代码:int data[3][4] = { {1,2,3,4}, {2,3,4,5}, {3,4,5,6}};int total = sum(data,3);sum这个函数的原型是:int sum(int (*arr)[4], int size)或者int sum(int arr[][4], int size)以上两个原型的含义原创 2014-03-28 10:49:27 · 725 阅读 · 0 评论 -
面向行的输入 getline()和get()的使用
1.getline()的使用:char name[20]; cin >> name; 如果用这种方式输入,当碰到输入诸如Dirk Hamernose这样分开的名字时,就会出现问题。只有使用char name[20]; cin.getline(name,20);这种方法可以解决输入复杂名字的情况。 getline()函数每次读取一行,它通过换行符原创 2014-03-16 18:51:51 · 895 阅读 · 0 评论 -
c++如何查询变量的类型
使用typeid().name()查询:#include #include using namespace std;int main(){ int a; char ch; char name[20]; string str; double b; long c; long long d; bool e; cout <原创 2014-03-19 18:15:47 · 15020 阅读 · 0 评论 -
用循环进行文本输入,EOF的使用
①选择一个特殊字符作为结束字符,有时候被称为哨兵字符。#include using namespace std;int main(){ char ch; int count = 0; cout << "Enter characters, enter # to quit: " << endl; cin >> ch; //读取输入的字符,并赋给ch,但是不能原创 2014-03-19 14:07:49 · 1810 阅读 · 0 评论 -
c++中EOF was not in this scope 的解决办法
在该c++文件的前面加上 #include 即可#include #include using namespace std;int main(){ int ch; int count = 0; cout << "Enter characters:" << endl; ch = cin.get(); while(ch != EOF) {原创 2014-03-19 13:39:32 · 883 阅读 · 0 评论 -
两个字符串地址的复制和内容的复制
❶地址的复制:char name[20];char new_name[20];new_name = name; ❷内容的复制:char name[20];char new_name[20];strcpy(new_name,name);原创 2014-03-17 19:55:23 · 814 阅读 · 0 评论 -
new和delete的使用
new 和 delete的使用: ❶基本格式: int * pn = new int; delete pn; //释放pn指向的内存,但是不会删除指针pn本身,可以讲pn重新指向一块新的内存块 ❷new的基本使用实例:#include using namespace std;int main(){ int *pn = ne原创 2014-03-18 11:14:46 · 558 阅读 · 0 评论 -
指针的用法
①基本概念:假设manly是一个指针,则manly表示的是一个地址,而*manly表示的是manly这个地在内存中所对应的 值。②指针简单程序实例:#include using namespace std;int main(){ int updates = 6; int *p_updates; p_u原创 2014-03-17 16:44:42 · 564 阅读 · 0 评论 -
结构体,联合体
1.结构体 ①结构体的定义:struct fruit{ char name[20]; char color[20]; float price;}; ②结构体创建变量:struct fruit{ char name[20]; char color[20]; float price;}apple, balana;或者原创 2014-03-17 12:45:39 · 591 阅读 · 0 评论 -
c++知识点小集
1.要让窗口一直打开,直到你按任何键,可在return语句前添加如下语句:cin.get();2.c++能够使用printf(),scanf()和其他所有标准c输入和输出函数,只需要包含常规c语言的stdio.h文件即可。3.如果编译器到达main()函数末尾时没有遇到返回语句,则认为main()函数以如下语句结尾: return 0; 这条隐含的返回 语句只适用于main()函数,原创 2014-03-13 23:33:44 · 572 阅读 · 0 评论 -
C++的存储持续性(自动、静态、动态),作用域,链接性
1.c++使用三种不同的方案进行数据的存储,z原创 2014-04-14 15:34:08 · 1800 阅读 · 0 评论 -
c++文件处理ofstream,ifstream
①将输出内容写入到文本中间中: 步骤:❶包含头文件fstream #include ❷创建一个ofstream对象(名字可以随意取,这里去做outFile) ofstream outFile; ❸将创建的对象outFile与某个文件关联起来 outFile.open("automobile.txt");原创 2014-03-21 14:28:41 · 2089 阅读 · 0 评论 -
cin.get()使用大全
①面向行的输入,输入一整行:char name[20], dessert[20];cin.get(name,20);cin.get();cin.get(dessert,20);②cin >> ch; 和 cin.get(ch)的区别cin >> ch; //在读取字符串中的字符时,不能读取空格cin.get(ch); //在读取字符串中的字符时,能够读取空格③ch = c原创 2014-03-19 14:27:15 · 1846 阅读 · 0 评论 -
climits 中的符号变量
在climits中有类似一下的语句:#define INT_MAX 32767INT_MAX使用实例:#include #include using namespace std;bool is_int(double x);int main(){ double num; int result; cout << "Enter an integer原创 2014-03-20 12:56:51 · 823 阅读 · 0 评论