随笔分类 -  c++

摘要:这个问题在很多书上都看到,只是后悔没早点看到...例如在《编程珠玑》,在《编程之美》,还在,有研究生入学考试里... 1 #include "stdafx.h" 2 #include <stdio.h> 3 #include <string> 4 5 //这种方法太浪费空间了,用了额外n个空间 6 void reverseStr(char *str,int n) 7 { 8 char* tmp = (char*)malloc(n*sizeof(char)) ;//定义n个临时空间存入要旋转的元素 9 unsigned int length = str 阅读全文
posted @ 2012-11-14 13:22 ifeixiang 阅读(405) 评论(1) 推荐(0) 编辑
摘要:void countSort(int &array) { int N = 1000000; int i ; double bit = 0 ; //用一个字符串来表示位向量 //先初始化位向量 //使用逻辑运算实现位向量,在保证其他位不变的情况下,将某位变成1,应该使用或运算,改变位为1,其他位都为0。使用移位运算 for( i = 0 ; i < N ; ++i) bit |= ( 1 << array[i] ) ; //再进行输出 fo... 阅读全文
posted @ 2012-11-13 20:10 ifeixiang 阅读(307) 评论(0) 推荐(0) 编辑
摘要:今天在看cocos2d的时候,看到Action的设计采用了组合模式和装饰模式,可以将一系列的action组合起来,让CCNodec对象执行,就像给CCNode下达一系列的命令一样.例如以下代码:1 CCActionInterval* move =CCMoveBy::actionWithDuration(0.5f, ccp(0,160)); 2 CCActionInterval*rotate = CCRotateBy::actionWithDuration(2, 360); 3 CCActionInterval*scale = CCScaleBy::actionWithDuration(2, 5 阅读全文
posted @ 2012-11-08 20:40 ifeixiang 阅读(421) 评论(0) 推荐(0) 编辑
摘要:1 #include 2 代码如下: 3 4 //使用ATL的W2A和A2W宏必须使用USES_CONVERSION 5 USES_CONVERSION; 6 7 //Unicode字符串 8 wchar_t* wszText=L"1.Unicode字符转换为ANSI;"; 9 printf("%s\n",W2A(wszText));10 11 //用wprintf输出非英文字符,需要设置当前的地域信息12 setlocale(LC_ALL,"chs");13 14 //ANSI字符串(ANSI:American National S 阅读全文
posted @ 2012-08-14 11:44 ifeixiang 阅读(2573) 评论(0) 推荐(0) 编辑
摘要:1. strlen(),计算字符串长度 1 int strlen(const char string) 2 3 { 4 5 int i=0; 6 7 while(string[i]) i++; 8 9 return i; 10 11 } 2. strcpy(), 字符串拷贝.1 char *strcpy(char *destination, const char *source) 2 3 { 4 5 while(*destinaton++=*source++); 6 7 return (destinat... 阅读全文
posted @ 2012-08-01 15:31 ifeixiang 阅读(295) 评论(0) 推荐(0) 编辑
摘要:—————————————VS2008快捷键大全—————————-Ctrl+m+Crtr+o折叠所有大纲Ctrl+M+Crtr+P: 停止大纲显示Ctrl+K+C: 注释选定内容Ctrl+K+U: 取消选定注释内容Ctrl+J : 列出成员 智能感知Shift+Alt+Enter: 切换全屏编辑Ctrl+B,T / Ctrl+K,K: 切换书签开关Ctrl+B,N / Ctrl+K,N: 移动到下一书签Ctrl+B,P: 移动到上一书签Ctrl+B,C: 清除全部标签Ctrl+I: 渐进式搜索Ctrl+Shift+I: 反向渐进式搜索Ctrl+F: 查找Ctrl+Shift+F: 在文件中查 阅读全文
posted @ 2012-07-16 18:57 ifeixiang 阅读(206) 评论(0) 推荐(0) 编辑
摘要:我写的第一句话: const应该改名叫readonly 除了可以修饰常量,const 更大的魅力是它可以修饰函数的参数、返回值,甚至函数的定义体。 const 是constant 的缩写,“恒定不变”的意思。 被const 修饰的东西都受到强制保护,可以预防意外的变动,能提高程序的健壮性。 所以很多C++程序设计书籍建议:“Use const whenever you need”。1.用const 修饰函数的参数如果参数作输出用,不论它是什么数据类型,也不论它采用“指针传递”还是“引用传递”,都不能加const 修饰,否则该参数将失去输出功能。const 只... 阅读全文
posted @ 2012-07-16 15:05 ifeixiang 阅读(372) 评论(0) 推荐(0) 编辑
摘要:宽字符库函数 我们都知道如何找出一个字符串的长度。例如,如果我们定义了一个指向字符串的指针:char * pc = "Hello!";我们可以调用iLength = strlen(pc);变量iLength会被设成6,也就是字符串中字符的个数。 好极了!现在让我们尝试定义一个指向宽字符串的指针:wchar_t * pw = L"Hello!"; 而且现在我们再次调用strlen:iLength = strlen(pw); 现在问题出现了。首先,C编译器会给你一个警告消息,大概是下面这个意思:'function' : incompatibl 阅读全文
posted @ 2012-07-16 10:16 ifeixiang 阅读(12293) 评论(0) 推荐(0) 编辑
摘要:今天在CSDN上看到的关于错误返回值的讨论,感觉非常有趣。 从中可以看出被教化的孩子与大神之间的区别...讨论如下: 先放上提问者的源程序: 这是第一种,做出判断后,如果条件出错,直接return...... 1 int mystrlen(char *str) 2 { 3 int count = 0; 4 if (str == NULL) 5 { 6 return -1; 7 } 8 9 if (*str == 0)10 {11 return 0;12 } 13 14 while(*str != 0 )15 ... 阅读全文
posted @ 2012-06-25 10:17 ifeixiang 阅读(2455) 评论(0) 推荐(1) 编辑
摘要:核心代码: 1 /** 2 * 利用cmd命令创建wifi热点 3 * */ 4 private void btCreateWifi_Click(object sender, EventArgs e) 5 { 6 string hotSpotName = wifiName.Text.Trim(); 7 string hotSpotPass = wifiPass.Text.Trim(); 8 if (hotSpotPass.Length < ... 阅读全文
posted @ 2012-05-18 21:53 ifeixiang 阅读(3097) 评论(0) 推荐(0) 编辑