win32中的宽字符

win32中的宽字符 宽字符 数据类型 容器、模板 ASCII 一个字符 一个字节 GB码(扩展了的ASCII) 英文字符 一个字节 GB码 中文字符 两个字节 UNICODE字符集(unicode编码实际指的是utf-16) 常用字符 两个字节 宽字符: 用多个字节来表示的字符称之为宽字符(只要不是以单字节存储都可称为……

Continue reading

unicode和utf8编码

兼容问题 由于ASCII存在字符含量过少的缺陷,所以不但我国自己搞出了国际码。其他国家也都设计出了符合自己国情的字符集 但是这就带来了问题 各个字符集之间不兼容怎么办? Unicode Unicode 4个字节32位 真正有效范围: 0x0 – 0x 10ffff 约十进制:1114112 个字符 unicode相当于 “区位码”(也就是电脑中运行……

Continue reading

GB2312原文到GB2312机内码

GB2312原文到GB2312机内码 ANSCII 汉字编码国家标准 区位码 01-09区 为特殊字符区 10-15区 为自定义区 16-87区 为汉字编码区 兼容演变: 1. 区位码标准中没有定义控制字符 解决方案: 将整个区位码向后移动32位(具体表现为每一字节都加上0x20)得到GB2312原码(国标码) 2. 原版A……

Continue reading

Cpp9 模板

模板 下面是一个针对int的冒泡排序 // _20180301.cpp : Defines the entry point for the console application. // #include "stdafx.h" void Sort(int* arr,int nLength) { int i,k; for (i = 0;ix > base.x && this->y > base.y; } private: int x; int y; }; template void Sort(T* arr,int nLength) { int i,k; for (i = 0;iy) return x; else return y; } M min() {……

Continue reading

Cpp8 运算符重载和深浅拷贝

深浅拷贝 相同类型间可以直接拷贝 // _20180212.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include class A { private: int* a; public: A() { a = new int[10]; } virtual ~A() { delete a; printf("析构 A \n"); } }; int main(int argc,char* argv[]) { A a1; A a2; a1 = a2; return 0; } //反汇编 27: A a1; 0040108D lea ecx,[ebp-14h] 00401090 call @ILT+15(B::B) (00401014) 00401095 mov dword ptr [ebp-4],0 28: A a2; 0040109C lea ecx,[ebp-1Ch] 0040109F call @ILT+15(B::B) (00401014) 004010A4 mov byte ptr [ebp-4],1 29: a1 = a2; 004010A8 lea eax,[ebp-1Ch] 004010AB push eax //a2 作为参数传递 004010AC lea ecx,[ebp-14h] //a1……

Continue reading

Ruby11 拾遗

Agenda Loop Expression File Read/Write Debug Process & Thread Loop while a = 10 while a > 0 puts a a -= 1 end until a = 100 until a == 0 puts a a -= 1 end loop a = 10 loop do break if a 0 !~ 正则匹配 是否匹配不到 匹配到返回fals 匹配不到返回true /666/i !~ "hello world" # => true alias 别名 def hello "hello" end alias old_hello hello def hello "new hello" end puts old_hello puts hello File Read/Write 文件读写 File.read File.readlines File#rewind etc IO.read/write File Read file = File.open("run.log", "r") while line = file.gets puts line end File Write file = File.open("run.log", "a+") file.puts "hello" file.close File.open("run.log", "a+") do……

Continue reading

Ruby10 Class Module Gem 深入

Agenda class_eval & instance_eval method_missing Module as a namespace Gems require vs load $LOAD_PATH class_eval 首先class_eval是只有类才能调用的,Class#class_eval class_eval会重新打开当前类的作用域 # class_eval class User end User.class_eval do attr_accessor :name def hello "hello" end end user = User.new user.name = "world" puts user.name puts user.hello # module"s self module Management def self.track "track" end end class User include Management end # User.track # => error Management.track # class_eval in project # requirement: we need to execute a class method when module included module Manegement def self.included……

Continue reading

Ruby9 Class & Modules 进阶

Ruby的内部类结构 Array.class # => Class Class.class # => Class superclass 查看父类 Array.superclass # =>Object Object.superclass # =>BasicObject BasicObject.superclass # => nil ancestors 查看当前类的继承链 Array.ancestors # => [Array, Enumerable, Object, Kernel, BasicObject] Method Finding 方法查找 # class structure, method finding class User def panels @panels ||= ["Profile", "Products"] end end class Admin < User end puts Admin.ancestors admin = Admin.new p admin.panels # 从下往上查找 在admin中查找 找不到往上找User 然后Object 然后Kernel 然后 BasicObject Method Overwrite 方法覆盖 class……

Continue reading

Ruby8 继承(Inheritance)和模块(Modules)

继承示例 # inheritance class User attr_accessor :name, :age def initialize name, age @name, @age = name, age end def panels # ||= 操作符, 如果变量不存在 那么就赋值 @panels ||= ["Profile", "Products"] end end class Admin < User def panels @panels ||= ["Profile", "Products", "Manage Users", "System Setup"] end end user = User.new("user_1", 18) p user.panels puts "-" * 30 admin = Admin.new("admin_1", 28) puts admin.name p admin.panels # 查看这个类的父类 p Admin.superclass 常用關鍵字 super关键字 调用父类的同名方法 self關鍵字 指向當前作用域實例 # inheritance class User attr_accessor :name, :age def initialize name,……

Continue reading

Ruby7 OOP

Everything is Object 一切皆对象 a = "hello" a.class # => String b = 3.14 b.class # => Float c = %w[pear cat horse] c.class # => Array Instance Method & Instance Attribute 实例方法,实例属性 Instance Method: 实例方法,成员方法,成员函数 Instance Attribute: 实例变量,成员属性,属性(property),使用@定义 # class class User def initialize name, age @name = name @age = age end # getter def name @name end def age @age end end user = User.new("Hello", 18) puts user.name puts user.age # class class User def initialize name, age @name = name @age = age end……

Continue reading