C++ 基础
文章平均质量分 51
Hustudent20080101
MFC Qt 瑞萨 ARM Linux
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
数组作为参数传递时,注意重载函数!
#include "iostream.h"class B{protected: char* name;public: B() { name="Class B"; } char* getName() { return name; }};class D:public B{private: int count;public: D() { name="C原创 2012-03-07 20:24:23 · 894 阅读 · 0 评论 -
sort 排序
// sort.cpp : Defines the entry point for the console application.//#include "stdafx.h"int a[]={1,3,5,7,9,8,7,5,2};int b[]={1,3,5,7,9,8,11,12,13};void swap(int& x,int& y){ int tmp=x; x=y; y=原创 2012-03-17 20:04:27 · 581 阅读 · 0 评论 -
链表打印
#include "stdafx.h"#include typedef struct _Node{ _Node(char *varname,_Node& prev,int isNexttoSb=1) { memset(name,0,256); strcpy(name,varname); if(isNexttoSb) prev.pNext=this; pNext=NU原创 2012-05-02 18:14:51 · 716 阅读 · 0 评论 -
c++强制类型转换:dynamic_cast、const_cast 、static_cast、reinterpret_cast
c++强制类型转换:dynamic_cast、const_cast 、static_cast、reinterpret_cast分类: C C++ STL2008-12-02 12:30 1398人阅读 评论(1) 收藏 举报dynamic_cast: 通常在基类和派生类之间转换时使用,run-time castconst_cast: 主要针对const和vo转载 2012-05-02 18:08:04 · 547 阅读 · 0 评论 -
链表,按序号检索
// ListTable.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include typedef struct _Node{ _Node(char *varname,_Node& prev,int isNexttoSb=1) { memset(name,0,原创 2012-05-02 18:36:12 · 730 阅读 · 0 评论 -
链表:插入,删除
// ListTable.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include typedef struct _Node{ _Node(char *varname,_Node& prev,int isNexttoSb=1) { memset(name,0,原创 2012-05-02 18:58:11 · 502 阅读 · 0 评论 -
链表:按序号插入、删除
// ListTable.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include typedef struct _Node{ _Node(char *varname,_Node& prev,int isNexttoSb=1) { memset(name,0,原创 2012-05-02 19:15:25 · 700 阅读 · 0 评论 -
静态链表:显示,插入
// staticList.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include typedef struct _Node{ void setName(char* p) { memset(name,0,256); strcpy(name,p); }原创 2012-05-02 21:35:16 · 587 阅读 · 0 评论 -
链表:多项式加和
// PolyList.cpp : Defines the entry point for the console application.//#include "stdafx.h"struct Item{ Item(int num,int power) { this->num=num; this->power=power; pNext=NULL; } int nu原创 2012-05-03 09:13:46 · 781 阅读 · 0 评论 -
链表:多项式相乘
// PolyList.cpp : Defines the entry point for the console application.//#include "stdio.h"struct Item{ Item(int num,int power) { this->num=num; this->power=power; pNext=NULL; } Item(It原创 2012-05-03 10:25:34 · 851 阅读 · 0 评论 -
链表:复杂链表的拷贝
// CopyComplexList.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include struct NameItem{ NameItem(char * name) { strcpy(this->name,name); pOther=NULL;原创 2012-05-03 22:18:29 · 809 阅读 · 0 评论 -
创建二叉树,并对其进行 先序、中序、后序遍历
//创建二叉树,并对其进行 先序、中序、后序遍历#include //#include typedef struct BiTNode { BiTNode(char* name) { strcpy(this->name,name); lchild=NULL; rchild=NULL; } BiTNode* InsertSbOnMyLeft(BiTNode* Sb) {原创 2012-05-05 19:36:14 · 2806 阅读 · 0 评论 -
反转一个链表。递归算法
//2、反转一个链表。递归算法。 #include #include struct List{ List(char * name) { strcpy(this->name,name); pnext=NULL; } List* InsertSbAfterMe(List* Sb) { Sb->pnext=this->pnext; this->pnext=S原创 2012-05-05 17:18:03 · 725 阅读 · 0 评论 -
反转一个链表。循环算法
//1、反转一个链表。循环算法。 #include #include struct List{ List(char * name) { strcpy(this->name,name); pnext=NULL; } List* InsertSbAfterMe(List* Sb) { Sb->pnext=this->pnext; this->pnext=Sb;原创 2012-05-05 16:17:01 · 748 阅读 · 0 评论 -
广度优先遍历二叉树
//3、广度优先遍历二叉树。 #include #include #include //int i =0;typedef struct treenode /*树节点结构体定义*/ { treenode(char* name) { strcpy(this->data,name);原创 2012-05-05 21:21:39 · 839 阅读 · 0 评论 -
“快速排序法”
// QuickSort.cpp : Defines the entry point for the console application.//#include "stdafx.h"//“快速排序法”使用的是递归原理,//下面我结合一个例子来说明“快速排序法”的原理。//首先给出一个数组{53,12,98,63,18,72,80,46, 32,21},//先找到第一个数--53,转载 2012-05-07 09:07:10 · 616 阅读 · 0 评论 -
实现strstr 函数
// strstr.cpp : Defines the entry point for the console application.//#include "stdafx.h"//*int strlen(char *str){ int len=0; while(*str) { str++; len++; } return len;}bool strIsRepe原创 2012-05-08 10:04:58 · 687 阅读 · 0 评论 -
实现strcmp 函数
// strcmp.cpp : Defines the entry point for the console application.//#include "stdafx.h"//、实现strcmp 函数。int strcmp(char* str1, char* str2){while(*str1 && *str2 && *str1==*str2){ ++str1; ++s转载 2012-05-08 10:13:15 · 756 阅读 · 0 评论 -
求一个整形中1 的位数。
// HowMany1s.cpp : Defines the entry point for the console application.//#include "stdafx.h"//求一个整形中1 的位数。int f( int x){ int n = 0 ; while (x) { ++ n; x &= x - 1 ; } return n;}int myfun转载 2012-05-08 10:34:47 · 1151 阅读 · 0 评论 -
InsertNodeAtPos(pHead,new List(7),7);//pos代表pHead后面第pos个节点
// sortList.cpp : Defines the entry point for the console application.//#include "stdafx.h"typedef struct List{ int data; List* pNext; List(int data) { this->data=data; pNext=NULL;原创 2012-05-09 14:13:37 · 1150 阅读 · 0 评论 -
SortList
// sortList.cpp : Defines the entry point for the console application.//#include "stdafx.h"typedef struct List{ int data; List* pNext; List(int data) { this->data=data; pNext=NULL;原创 2012-05-09 12:29:31 · 535 阅读 · 0 评论 -
静态循环链表【数组】
// StaticQuene.cpp : Defines the entry point for the console application.//#include "stdafx.h"struct StaticQuene{private: char buff[10]; int front; int rear;public: bool isFull; bool isEmp原创 2012-05-09 20:54:28 · 703 阅读 · 1 评论 -
StaticQuene//int getLength()
// StaticQuene.cpp : Defines the entry point for the console application.//#include "stdafx.h"struct StaticQuene{private: char buff[10]; int front; int rear;public: bool isFull; bool isEmp原创 2012-05-09 21:31:18 · 601 阅读 · 0 评论 -
面向对象的思想
面向对象的思想:面向对象是软件开发出现以来最伟大的创新之一,这是每个程序员都追求的,但是否真正掌握了面向对象的思想,这是需要探讨的。面向对象并不受开发工具和语言的限制。很多程序员在用C++写面向对象的代码时候,实际上还是在写C代码。甚至使用C#这种完全面向对象的语言写出来的还是流程化的程序。很多时候学习面向对象用屏幕上画图的方法,新的形状可以从标准的形状中转化而来,用来学习继承转载 2012-05-14 21:36:19 · 510 阅读 · 0 评论 -
c内嵌汇编
#include "stdio.h"#include "conio.h"short pow_16(short a, short b)算的是a*2^(b-1). { short result; --b; __asm{ mov ax, a; mov cx, b; s: add ax, ax;转载 2012-06-03 09:56:14 · 660 阅读 · 0 评论 -
最大公约数
// commonDivisor.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include #include int getcd(int u,int v) { int r; while(v!=0) { r=u%v; u=v; v=r原创 2012-06-06 15:40:41 · 726 阅读 · 1 评论 -
inline 函数
// FunsPointArry.cpp : Defines the entry point for the console application.//#include "stdafx.h"inline int f1(int a){ printf("f1:%x\n",f1); return a;}inline int f2(int a){ printf("f2:%x\n原创 2012-05-20 10:06:36 · 507 阅读 · 0 评论 -
inline;static
// FunsPointArry.cpp : Defines the entry point for the console application.//#include "stdafx.h"inline int f1(int a){ static int counter=0; printf("f1:%x,%d\n",&counter,++counter); printf("f1原创 2012-05-20 10:20:56 · 693 阅读 · 0 评论 -
原码、反码、补码和移码其实很简单
最近在备战软考,复习到计算机组成原理的时候,看到书中关于原码、反码、补码和移码的定义如下(n是机器字长):原码:反码:补码:移码:看完这些定义以后,我的脑袋瞬间膨胀到原来的二倍!这样变态的公式不管你记不记得住,反正我是记不住!还好以前对它们转载 2012-05-24 10:32:37 · 1069 阅读 · 0 评论 -
#define #undef
// Define.cpp : Defines the entry point for the console application.//#include "stdafx.h"int main(int argc, char* argv[]){#define A 15 printf("%d!\n",A);#undef A#define A 16 printf("%d!\n",原创 2012-05-24 08:39:00 · 796 阅读 · 0 评论 -
UNICODE,_UNICODE
else { // TODO: code your application's behavior here. CString strHello; strHello.LoadString(IDS_HELLO); cout << (LPCTSTR)strHello << endl; TCHAR str[256]=_TEXT("HelloWorld\n"); _tprintf(原创 2012-06-27 21:20:20 · 588 阅读 · 0 评论 -
ASCII 码值表
ASCII 码值表 Char Dec Oct Hex | Char Dec Oct Hex | Char Dec Oct Hex | Char Dec Oct Hex-----------------------------------------------------------------------------------(nul) 0 0000 0x00转载 2012-07-18 19:56:29 · 1197 阅读 · 0 评论 -
__try,__except,__finally,__leave
__try,__except,__finally,__leave导读: 从本篇文章开始,将全面阐述__try,__except,__finally,__leave异常模型机制,它也即是Windows系列操作系统平台上提供的SEH模型。主人公阿愚将在这里与大家分享SEH的学习过程和经验总结。 SEH有两项非常强大的功能。当然,首先是异常处理模型了,因此,这篇文章首先深转载 2012-07-20 21:16:28 · 1101 阅读 · 0 评论 -
系统异常,也被称为硬件异常;还有一类,就是程序中自己抛出异常,被称为软件异常
最后还有一点需要阐述,在C++的异常处理模型中,有一个throw关键字,也即在受监控的代码中抛出一个异常,那么在SEH异常处理模型中,是不是也应该有这样一个类似的关键字或函数呢?是的,没错!SEH异常处理模型中,对异常划分为两大类,第一种就是上面一些例程中所见到的,这类异常是系统异常,也被称为硬件异常;还有一类,就是程序中自己抛出异常,被称为软件异常。怎么抛出呢?还是Windows提供了的API函转载 2012-07-21 08:32:50 · 1581 阅读 · 0 评论 -
try-catch 处理异常,也即 C++ 异常处理
// 注意,这是 C++ 程序,文件名为: SEH-test.cpp#include "stdio.h"class A{public: void f1() {} // 抛出 C++ 异常 void f2() { throw 888;}};// 这个函数中使用了 try-catch 处理异常,也即 C++ 异常处理void test1(){A a1;A a2,a3; t转载 2012-07-21 10:07:56 · 639 阅读 · 0 评论 -
SEH 与 C++ 异常模型的混合使用
// 注意,这是 C++ 程序,文件名为: SEH-test.cpp#include "stdio.h"class MyException{public: MyException() {printf(" 构造一个 MyException 对象 \n");} MyException(const MyException& e) {printf(" 复制一个 MyExceptio转载 2012-07-21 10:18:21 · 726 阅读 · 0 评论 -
// 捕获得到吗? catch(...)
#include class MyException{public: MyException() {printf(" 构造一个 MyException 对象 \n");} MyException(const MyException& e) {printf(" 复制一个 MyException 对象 \n");} operator=(const MyException& e) {pri转载 2012-07-21 10:25:35 · 568 阅读 · 0 评论 -
一个函数只能采用一种形式的异常处理规则
// 注意,这是 C++ 程序,文件名为: SEH-test.cpp#include "stdio.h"void main(){int* p = 0x00000000; // pointer to NULL// 这里是 SEH 的异常处理语法 __try { puts("in try"); // 这里是 C++ 的异常处理语法 try { puts("in try转载 2012-07-21 10:30:14 · 1111 阅读 · 0 评论 -
__try { A a1, a2;//注释掉~A()就好了
#includeclass A{public: A() {printf(" 构造一个 A 对象 \n");} //~A() {printf(" 析构一个 A 对象 \n");} void f1() {} void f2() {}};void main(){ __try { //int a1, a2;//允许int //A a1, a2;//不允许A A a1, a2原创 2012-07-21 10:45:12 · 646 阅读 · 0 评论 -
__except(exception_int_divide_by_zero_filter(GetExceptionInformation()))
#include #include #include int exception_access_violation_filter(LPEXCEPTION_POINTERS p_exinfo){ if(p_exinfo->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) { printf("存储保护异常\n"原创 2012-07-20 22:00:17 · 1368 阅读 · 0 评论
分享