05 2012 档案
摘要:下面举个例子吧!eg:local tabFiles = {[3] = "test2",[6] = "test3",[4] = "test1"}for k, v in ipairs(tabFiles) doprint(k, v)end猜测它的输出结果是什么呢?根据刚才的分析,它在ipairs(tabFiles) 遍历中,当key=1时候value就是nil,所以直接跳出循环不输出任何值。>lua -e "io.stdout:setvbuf 'no'" "Test.lua"&g
阅读全文
摘要:bool IsToday(time_t nLastTime, time_t nNowTime){time_t LastTime = nLastTime;struct tm localTime;localtime_r(&LastTime, &localTime);time_t NowTime = nNowTime;struct tm localNowTime;localtime_r(&NowTime, &localNowTime);if (localTime.tm_year == localNowTime.tm_year &&localTime.t
阅读全文
摘要:#include <vector>#include <iostream>#include "compacket.h"#include <map>using namespace std;struct Activity{int m_nStep;int m_nCount;Activity():m_nStep(1),m_nCount(0){}Activity(const int nStep,const int nCount):m_nStep(m_nStep = nStep),m_nCount(m_nCount = nCount){}};int m
阅读全文
摘要:#include <iostream>using namespace std;class A{public:A(double _data = 0.0) :data(_data){}A& operator =(const A& rhs){data = rhs.data;return *this;}friend A operator +(const A& lhs, const A& rhs);friend A operator -(const A& lhs, const A& rhs);friend A operator *(const
阅读全文
摘要:#include using namespace std;class A{public: A(double _data = 0.0) : data(_data) { } A& operator =(const A& rhs) { da...
阅读全文
摘要:void str(char * a){char *toks = " ";char * tok = strtok(a, toks);while (tok){if (tok == a)strcpy(a, tok);elsestrcat(a, tok);tok = strtok(NULL, toks);}}int main(){string b = "this is a dog";str(const_cast<char*>(b.c_str()));cout<<b;return 0;}#include <iostream> #
阅读全文
摘要:#include <vector>#include <iostream>#include "compacket.h"using namespace std;char szBuf[4096];const int INT = 4;const int STRING = 100;void EncodeMsg(char *pPos){int tmp = 80000;memcpy((void *) pPos, (void *) &tmp, INT);pPos+=INT;char Role[] = "艾迪";memcpy((void *
阅读全文
摘要:#include <vector>#include <iostream>#include <iterator>using namespace std;int main(){int N = 2, M = 3;vector<vector<int> > Matrix(N, vector<int> (M, 0));ostream_iterator<int> os(cout, " ");Matrix[0][2] = 4;//交换矩阵的两行Matrix[0].swap(Matrix[1]);//交换矩阵
阅读全文
摘要:#include <iostream>#include <string.h>using namespace std;int main(){unsigned char input[50];cin >> input;int flag = 0;for (int i = 0; i < 50; i++){if (input[i] > 0xa0 && input[i] != 0){if (flag == 1){cout << "chinese character" << endl;flag = 0;
阅读全文
摘要:#include <iostream>#include <string.h>using namespace std;int main(){string result;string s ( "AAAAAAAA" );char ch = 'C';result = s.replace ( 1 , 3 , 4 , ch ); // s= "ACCCCAAAAcout<<s<<endl;return 0;}
阅读全文
摘要:1. 《代码大全》史蒂夫·迈克康奈尔推荐数:1684“优秀的编程实践的百科全书,《代码大全》注重个人技术,其中所有东西加起来,就是我们本能所说的“编写整洁的代码”。这本书有50页在谈论代码布局。” —— Joel Spolsky对于新手来说,这本书中的观念有点高阶了。到你准备阅读此书时,你应该已经知道并实践过书中99%的观念。– esac2. 《程序员修炼之道》推荐数:1504对于那些已经学习过编程机制的程序员来说,这是一本卓越的书。或许他们还是在校生,但对要自己做什么,还感觉不是很安全。就像草图和架构之间的差别。虽然你在学校课堂上学到的是画图,你也可以画的很漂亮,但如果你觉得你不太
阅读全文
摘要:代码审查:正如我在上一篇博客中提到的(现在可以明确地告诉大家),我已经离开Google了。虽然我已经收到了很多不错的offer,但是还没有决定去哪里。在这段时间里从技术角度上说我不受雇于任何人,虽然也许这会让我和(前)同事或者老板关系有点紧张,但我觉得应该写一些关于技术上的有趣的事情。Google确实是一家很酷的公司。不论是在公司内部或是外部,Google都做了很多让人赞叹的的事情。这里我想介绍一些不涉及商业机密,但鲜为外人所知的事情。Google的代码之所以优秀原因其实很简单:他们非常重视代码审查。代码审查并不是Google独有的,它被公认为是一个很好的(提高代码质量的)手段,很多人已经在日
阅读全文
摘要:代码之美,不仅在于为一个给定问题找到解决方案,而且还在代码的简单性、有效性、紧凑性和效率(内存)。代码设计比实际执行更难 。因此,每一个程序员当用C语言编程时,都应该记着这些东西。本文向你介绍规范你的C代码的10种方法。0. 避免不必要的函数调用考虑下面的2个函数:12345678910111213141516171819202122232425262728voidstr_print(char*str ){ inti;for( i = 0; i <strlen( str ); i++ ) {printf("%c",str[ i ] ); }} voidstr_prin
阅读全文
摘要:unsigned int ui_one = 1;signed int i_one = 1;signed short s_minus_one = -1;if (s_minus_one > ui_one)printf("-1 > 1\n");if (s_minus_one < i_one)printf("-1 < 1\n");#./run## -1 > 1# -1 < 1int array[] ={ 0, 1, 2, 3, 4 };int *pointer = array;if (sizeof(array) == size
阅读全文
摘要:我的程序在运行过程中会同时向磁盘写两个体积很大的二进制文件。文件A大致是240G,文件B大致是480G。两个文件都是用ofstream对象来维护的。写操作是通过ofstream的write成员函数实现的。现在的问题是:每次写文件写到64%左右就会出错,write函数的返回值显示写操作没有成功。第一回是在文件A出错,第二回则是在文件B出错。刚好这几天单位这边的电路在整改。程序两次出错,都正好是电工对配电箱进行操作、对中央空调和好几个房间的电路进行合闸开闸的时候。所以不知道有没有可能是电压不稳而导致磁盘写操作失败。但是我的房间并没有停电,也就是说电脑并没有停机,所以感觉很奇怪。目前已经排除了单个文
阅读全文
摘要:ofstream写大文件出错 我的程序在运行过程中会同时向磁盘写两个体积很大的二进制文件。文件A大致是240G,文件B大致是480G。两个文件都是用ofstream对象来维护的。写操作是通过ofstream的write成员函数实现的。 现在的问题是:每次写文件...
阅读全文
摘要://testprocess.c#include <stdio.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <errno.h>#include <sys/file.h>#include <string.h>int main(){int fd;char path[] = "/data/aidi_slave_s001a/backup/test.txt"
阅读全文
摘要:/************************************* 版权声明* 本文为本人原创,本人拥有此文的版权。鉴于本人持续受益于开源软件社区,* 本人声明:任何个人及团体均可不受限制的转载和复制本文,无论是否用于盈利* 之目的,但必须在转载及复制时同时保留本版权声明,否则为侵权行为,本人保* 留追究相应法律责任之权利。* speng2005@gmail.com* 2007-12************************************/ 近日在使用ACE进行开发的工作中遇...
阅读全文
摘要:#include <stdio.h>#include <string>#include <stdlib.h>#include <iostream>#include <map>#include <vector>using namespace std;typedef map<int, int> templatemap;templatemap ScoreSort;int GetPOS(templatemap Sort, int nRoleID){if (Sort.find(nRoleID) == Sort.end()
阅读全文