![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++
爱吃的小花猫
来者皆客
展开
-
c++: Does the new operator for dynamic allocation check for memory safety?
Quesion:My question arises from one of my c++ exercises (from Programming Abstraction in C++, 2012 version, Exercise 12.2). Here it is:void strcpy(char *dst, char *src) { while (*dst++ = *sr原创 2015-03-25 11:02:41 · 1400 阅读 · 1 评论 -
C++ The Bisection Method
C++语言中的二分查找法算法:当数据量很大适宜采用该方法。采用二分法查找时,数据需是排好序的。基本思想:假设数据是按升序排序的,对于给定值x,从序列的中间位置开始比较,如果当前位置值等于x,则查找成功;若x小于当前位置值,则在数列的前半段中查找;若x大于当前位置值则在数列的后半段中继续查找,直到找到为止。假如有一组数为3,12,24,36,55,68,75,88要查给定的值原创 2015-03-16 07:04:08 · 1916 阅读 · 0 评论 -
C++中的class
C++中的class是C++不同于C的关键所在;是面向对象中声明的类; 公有成员public member 在程序的任何地方都可以被访问实行信息隐藏的类将 其public 成员限制在成员函数上这种函数定义了可以被一般程序用来操纵该类类型对象的操作 私有成员private member原创 2015-03-13 11:24:52 · 51152 阅读 · 0 评论 -
C++中的class (1)
1、public:public表明该数据成员、成员函数是对所有用户开放的,所有用户都可以直接进行调用2、private:private表示私有,私有的意思就是除了class自己之外,任何人都不可以直接使用,私有财产神圣不可侵犯嘛,即便是子女,朋友,都不可以使用。 3、protected:protected对于子女、朋友来说,就是public的,可以自由使用,没有任何限制,而原创 2015-03-14 03:04:14 · 752 阅读 · 0 评论 -
C++类和对象的一个简单的实例
#include usingnamespace std; classArray_max{ private://声明在类的外部不可访问的隐私成员 intarray[10]; intmax; public://声明在类的外部可以访问的开放的成员函数原创 2015-03-14 19:48:37 · 903 阅读 · 0 评论 -
Class 找出一个整形数组中的元素的最大值
目的:找出一个整形数组中的元素的最大值 下面,我们用类和对象的方法来做。 #include using namespace std; class Array_max{ private://声明在类的外部不可访问的隐私成员 int array[10]; int max; public://声明在原创 2015-03-14 19:43:56 · 5357 阅读 · 0 评论 -
C++的class的例子
私有就是只能够通过内部调用,在类外面是不可以使用私有成员的简单的写一个 Class A{ public: //你可以通过公有的函数去访问私有成员 Demo() //可以在这使用私有成员 { m_buff = 0; } private: //私有成员 int m_buff;}void main(){ A a原创 2015-03-14 18:04:53 · 893 阅读 · 0 评论 -
C++ 字符串的声明和赋值 以及易错点
C++的字符串,不仅初学者常犯错误,连老手都会出错。所以我想系统的把一些基本知识和易错点都写出来,仅供参考char a [5]={'H','E','L','L','O'};//只能在数组声明时使用当然,可以省去声明长度。char a[] ={'H','E','L','L','O'};char a[]="HELLO"; 和char a[]="HELLO\0";等价原创 2015-03-03 15:46:40 · 66613 阅读 · 3 评论 -
C++中public、protected及private用法
1.类的一个特征就是封装,public和private作用就是实现这一目的。所以:用户代码(类外)可以访问public成员而不能访问private成员;private成员只能由类成员(类内)和友元访问。2.类的另一个特征就是继承,protected的作用就是实现这一目的。所以:protected成员可以被派生类对象访问,不能被用户代码(类外)访问。现来看看如下示例:原创 2015-03-13 11:37:02 · 13605 阅读 · 0 评论 -
指针 (整理版)
指针是C/C++编程中的重要概念之一,也是最容易产生困惑并导致程序出错的问题之一。利用指针编程可以表示各种数据结构,通过指针可使用主调函数和被调函数之间共享变量或数据结构,便于实现双向数据通讯;指针能够灵活的操作内存,合理的操作内存能够使程序更高效。1.指针的概念 本质上讲指针也是一种变量,普通的变量包含的是实际的数据,而指针变量包含的是内存中的一块地址,这块地址指向某个变量或者函数,原创 2015-03-16 13:56:20 · 2611 阅读 · 0 评论 -
atoi C语言的基本用法 code
#include #include int main(void){ float n; char const *str = "12345.67"; n = atoi(str); printf("string=%sint=%dfloat=%f\n",str,n,n); return 0;原创 2015-03-20 12:58:48 · 611 阅读 · 1 评论 -
命名空间std::的例子
C++代码#include using namespace std; // 命名空间Saskatchewan namespace Saskatchewan{ char *szUrl = "www.Saskatchewan.com"; } // 命名空间 player namespace player{ char *szU原创 2015-03-20 14:15:57 · 384 阅读 · 0 评论 -
std::的概念与作用
std::其中std是名称空间,防止重复。比如说许多人给函数取名可能都叫f1();你使用的时候就可能造成问题。如果各人均把自己的f1()放进自己的名称空间,我们在使用的时候带上名称空间就不会有问题。主要是起到了资源管理的作用,下面是一个例子:有两个软件公司A公司和B公司,他们都是用C++语言开发他们的产品。那么,他们分别编写了a.h和b.h两个自己的头文件,这两个文件中都有一个原创 2015-03-20 13:44:13 · 10196 阅读 · 1 评论 -
命名空间std::的例子(2)
int x = 20; namespaceouter { intx = 10; namespaceinner { intz = x; } } int main() { std::cout << outer::inner::z;// 输出10 return 0;原创 2015-03-20 15:00:55 · 690 阅读 · 0 评论 -
C++继承经典例子
c++继承经典例子#include class Base{private: int b_number;public: Base( ){} Base(int i) : b_number (i) { } int get_number( ) {return b_number;} void p原创 2015-03-17 08:33:14 · 3278 阅读 · 1 评论 -
C语言100个经典的算法
C语言的学习要从基础开始,这里是100个经典的算法-1C语言的学习要从基础开始,这里是100个经典的算法题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?______________________________________________原创 2015-03-13 22:38:25 · 7988 阅读 · 3 评论 -
Class C++
为了尽量减少全局变量的使用并提供用户自定义类型的功能,C++语言提供了一种新的语言机制---类(class),并以类作为构造程序的基本单位#includeusing namespace std;class C{public:int getAge()const{return age;};void setAge(int n){age=n;}原创 2015-03-17 11:18:26 · 1036 阅读 · 1 评论 -
What is the name of the “-->” operator?(Stackoverflow)
Question:After reading Hidden Features and Dark Corners of C++/STL on comp.lang.c++.moderated, I was completely surprised that it compiled and worked in both Visual Studio 2008 and G++ 4.4.T原创 2015-03-21 01:27:53 · 3898 阅读 · 0 评论 -
Conditionals with Omitted Operands (x ? : y)
Conditionals with Omitted OperandsThe middle operand in a conditional expression may be omitted. Thenif the first operand is nonzero, its value is the value of the conditionalexpression.Therefor原创 2015-03-21 00:42:10 · 3761 阅读 · 0 评论 -
Conditionals with Omitted Operands (x ? : y) example
#include int f(int x){ return x?:1;}int main(){ printf("f %d\n", f(0)); printf("f %d\n", f(1)); return 0;}//output:f 1f 1//And when I change it to int f(in原创 2015-03-21 00:47:29 · 3849 阅读 · 1 评论 -
tolower (Function)
this is a function that Convert uppercase letter to lowercaseConverts c to its lowercase equivalent if c is an uppercase letter and has a lowercase equivalent. If no such conversion is possibl原创 2015-03-21 01:11:31 · 3899 阅读 · 0 评论 -
Why is processing a sorted array faster than an unsorted array(Stackoverflow)
What is Branch Prediction?Consider a railroad junction:Image by Mecanismo, via Wikimedia Commons. Used under the CC-By-SA 3.0 license.Now for the sake of argument, suppose this is back in th原创 2015-03-21 02:03:53 · 4044 阅读 · 0 评论 -
浅谈分支预测、流水线与条件转移
在StackOverflow上有这么一个问题 Why is processing a sorted array faster than an unsorted array? 。例子中,对一个数组进行条件求和,在排序前和排序后,性能有很大的差别。原始的例子是C++和Java的,这里将其换成了C# :static void Main(string[] args){ // Genera转载 2015-03-21 02:27:44 · 5169 阅读 · 1 评论 -
vim cheat sheet
原创 2015-03-21 04:16:26 · 2055 阅读 · 0 评论 -
vim note (1)
'vim' go into the vim mode'i' 'a' 's' is means insert mode'v' is means visual mode'esc' is means back to normal modej down k uph leftl right原创 2015-03-21 04:21:57 · 1234 阅读 · 0 评论 -
vim note(3)
Ctrl+w Ctrl+v will create a new window on the right side of the current windowCtrl+w Ctrl+s will create a new window on the down side of the current window(Ctrl+w)^2 press twice, go原创 2015-03-21 04:42:12 · 903 阅读 · 1 评论 -
vim note (2)
:e edit:edit edit:e. edit current file '.' a dot is means current: w write: x save &exit: q quit: q! quit anywayshift * high the current wordw forwo原创 2015-03-21 04:38:08 · 774 阅读 · 1 评论 -
vim 学习总结
vim ~/.vimrc vim Student.cc首先,Mac系统默认已经安装了Vim。打开终端,输入vim,回车。可看到如下界面,即表示Vim已经安装了。在vim里输入":q" 在终端上,界面非常之简洁,如果你需要更加复杂的界面以及使用Vim更多的特性,需要下载客户端安装。在Mac上目前存在两个版本的Vim客户端: 1、转载 2015-03-21 04:46:30 · 4702 阅读 · 0 评论 -
vim note(5)
.vimrc 的设置$HOME/.vimrc 的普通设置,如下。set nocompatible "" not compatible with VI"" Encodings and fontsset encoding=utf-8set fileencoding=utf-8set fileencodings=ucs-bom,gb18030,gbk,gb2312,cp936原创 2015-03-21 06:23:03 · 915 阅读 · 0 评论 -
int**a = new int[5][6] 怎么delete
int **a = new int[5][6],这个根本编译不过去吧。如果你想new一个二维数组出来,应该这样:int** a= new int*[5];for (int i = 0; i { a[i] = new int[6];}delete的时候,反过来就行了:for (int i = 0; i { delete[]原创 2015-03-29 12:50:53 · 1249 阅读 · 1 评论 -
exit return区别(2)
1. return返回函数值,是关键字; exit 是一个函数。2. return是语言级别的,它表示了调用堆栈的返回;而exit是系统调用级别的,它表示了一个进程的结束。3. return是函数的退出(返回);exit是进程的退出。4. return是C语言提供的,exit是操作系统提供的(或者函数库中给出的)。exit是一个库函数,exit(1)表示发生错误后退出程序,exit(0原创 2015-03-12 08:03:10 · 546 阅读 · 0 评论 -
return 和exit(0)的区别
return是返回函数调用,如果返回的是main函数,则为退出程序,exit是在调用处强行退出程序,运行一次程序就结束, 无论写在那里.原创 2015-03-12 08:01:33 · 10364 阅读 · 0 评论 -
I/O Input and Output
库自动定义了一些标准对象:cout, ostream类的一个对象,可以将数据显示在标准输出设备上.cerr, ostream类的另一个对象,它无缓冲地向标准错误输出设备输出数据.clog, 类似cerr,但是它使用缓冲输出.cin, istream类的一个对象,它用于从标准输入设备读取数据.库允许编程人员利用ifstream和ofstream类进行文件输入和输出.原创 2015-03-12 07:47:49 · 24668 阅读 · 0 评论 -
面向对象和面向过程 不同之处
对于不同的语言来说:C是面向过程 C++ JAVA是面向对象C程序的设计首要考虑的是如何通过一个过程,对输入(或环境条件)进行运算处理得到输出(或实现过程(事务)控制)C++,首要考虑的是如何构造一个对象模型,让这个模型能够契合与之对应的问题域,这样就可以通过获取对象的状态信息得到输出或实现过程(事务)控制。面向对象和面向过程的区别原创 2015-03-11 16:50:16 · 1208 阅读 · 0 评论 -
电脑术语 IT人员必知
absence 缺席access访问存取通路进入achieve 实现完成acquire 获得adjacency list method 邻接表表示法adjacency matrix method 邻接矩阵表示法algorithm 算法allocate 留下分配analog 推论append 添加archive 档案归档原创 2015-03-12 02:14:26 · 3024 阅读 · 0 评论 -
C++ 指针详解(2)
一、指针运算符*和 &地址运算符eg: y=&x; z = *y; x 的值为1000,x 的地址为551.&地址运算符是一元运算符,反回它的操作数的内存地址.y 将接收到地址55.2.*指针运算符是一元运算符,它是&运算符的相反形式,*运算符能反回位于其操作数所指定的地址的变量的值.即只要*后面是地址(任何形式),*都返回地址对应的值。原创 2015-03-10 15:58:13 · 1732 阅读 · 0 评论 -
C/C++基本数据类型
基本类型C/C++语言有一组基本类型,对应于计算机的基本存储单元和使用这些单元去保存数据的一些常用方式:基本数据类型如下:NameDescriptionSize*Range*charCharacter or small integer.1bytesigned: -128 to 127unsigned: 0 to原创 2015-03-10 15:51:13 · 1508 阅读 · 0 评论 -
第二章 Big O notation 试题以及讲解 (包会)
这里列出了一些难做的题或是易错的题,简单的我就没有过多的解释,但是如果大家有任何问题都可以私信我或是评论一下,我会尽量即时的解答问题或是疑问的。int x=0; for(int i=4*n; i>=1; i--) x=x+2*i; O(n)The loop runs O(n) times and does O(1) work per iter原创 2015-03-07 14:24:35 · 5350 阅读 · 1 评论 -
第三章 Standard Template Library,标准模板库(高级版)
第一部分:(参考百度百科) 一、STL简介STL(Standard Template Library,标准模板库)是惠普实验室开发的一系列软件的统称。它是由Alexander Stepanov、Meng Lee和David R Musser在惠普实验室工作时所开发出来的。现在虽说它主要出现在C++中,但在被引入C++之前该技术就已经存在了很长的一段时间。原创 2015-03-08 17:12:17 · 51582 阅读 · 0 评论 -
第二章 Big O notation 进阶课程
第二章 Big O notation 进阶课程在这一章中,我们将会了解到算法的基础----Counting primitive operation,什么是primitive operation:The following are all primitive operations:1. Assigning a value to a variable2. Calling ano原创 2015-03-07 14:02:12 · 4374 阅读 · 0 评论