验证demo

// chenwenjun.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <list>

//.........结构体指针的使用 和 list缓存指针
//struct Test
//{
// int len;
// char* point;
//};
//
//class A
//{
//public:
// A(){}
// ~A(){}
//
// void push();
// void pop();
//private:
// std::list<Test*> test_list_;
//};
//
//
//void A::push()
//{
// Test* test = new Test;
// test->len = 1995;
// test->point = new char[1995];
// test_list_.push_back(test);
//}
//
//void A::pop()
//{
// Test* test = test_list_.front();
// std::cout << test->len << std::endl;
//}
//
//int main()
//{
// A a;
// a.push();
// a.pop();
//
// system("pause");
//}

//...........二级指针申请内存,相当于二维数组
//struct A
//{
// int a;
//};
//
//int main()
//{
// A* a = new A[100];
// a[2].a = 100;
// //a[101].a = 101;
//
// A** aa = (A**) new int[100];
// for (int i = 0; i< 100; i++)
// {
// aa[i] = new A();
// }
// //aa[99][998].a = 1;
// aa[0][2000].a = 1;
//
//
// std::cout << a[2].a << std::endl;
// std::cout << aa[0][2000].a << std::endl;
// system("pause");
//}

//...................若想改变指针的地址需要传 二级指针 或者 一级指针的引用
// void test(char *p)
//
// {
//
// printf("[test1][p]:%p.\n", p);
//
// printf("[test2][p]:%s.\n", p);
//
// p = (char *)malloc(10);
//
// strcpy(p, "ABCDE");
//
// printf("[test3]malloc之后.....\n");
//
// printf("[test4][p]:%p.\n", p);
//
// printf("[test5][p]:%s.\n", p);
//
// free(p);
//
// }
//
//
//
// int main()
//
// {
//
// char b[6] = "abcde";
//
// char *a = b;
//
// printf("[main1][a]:%p.\n", a);
//
// printf("[main2][a]:%s.\n", a);
//
// test(a);
//
// printf("[main3][a]:%p.\n", a);
//
// printf("[main4][a]:%s.\n", a);
//
//
// system("pause");
// return 0;
//
// }

//......对象无法访问私有析构函数, list内是指针时,需要对迭代器取*
// struct S
// {
// int a;
// };
//
//
// class A
// {
// public:
// A() {
//
// }
// private:
// ~A()
// {
// std::cout << "ok...!\n";
// }
//
// };
//
// int main()
// {
// std::list<S*> s_list_;
// S s;
// s_list_.push_back(&s);
//
// for (std::list<S*>::iterator iter; iter != s_list_.end(); iter++)
// {
// S* s = *iter;
// std::cout << s->a << std::endl;
// std::cout << (*iter)->a << std::endl;
// }
//
//
//
// return 0;
// }

//..........int型强赋值给char型后会发生什么
// int main()
// {
// char a[10];
// a[0] = 2;
// //printf("%d\n", a[0]);
//
// if (2 == a[0])
// {
// std::cout << (int)a[0] << std::endl;
// printf("%d\n", a[0]);
// }
// system("pause");
// }
//........... 长字节赋给短字节有可能会被截断,例如char是一个字节,int为4个字节,
// 2在内存中其实是 00000000 00000000 00000000 00000010,char只获取 00000010,因此还没被截断,
// 超过255就会被截断。std::cout会默认匹配类型打印,a实际是个数组,若只想打印a[0],需要强转int

上一篇:全局最小割StoerWagner算法详解


下一篇:IE6浏览器不支持固定定位(position:fixed)解决方案(转)