随笔分类 - [技术]c/c++
摘要:【转自】http://blog.csdn.net/poechant/article/details/6618284# Thrift可以实现C++、Java、Python等多种语言的自动生成,此处以C++为例。 1. 编写[.thrift]文件 将代码保存为student.thrift文件。 stru
阅读全文
摘要:昨天输出string类型时总是出错,发现输出到文件的一行里多了^@,输出到console却看不到,debug发现,string类型中多了\000,这主要由于我想要用\0截掉字符串最后一位,所以把字符串的最后一位换成了\0,却发生了错误。
例如: string tmp = “Hello;” string tmp2 = "World"
我想得到:...
阅读全文
摘要:因为要用到,但发现Java怎么都收不到C发来的数据,除非C端自动挂掉,java会一口气全收回来。
后来才发现是因为C发过来的Java用readline是读不到回车的,所以会一直等待。
所以不要用readline(),这是不正确滴。
具体应该如下:
Java Server端: 1 package jsi; 2 3 import java.io.BufferedReader; 4 impo...
阅读全文
摘要:模板模式(template)在面向对象系统的设计和开发过程中,一定会有这样的情况:对于一些功能,在不同的对象身上展示不同的作用,但是功能的框架是一样的,这就是模板(template)模式的用武之地,我说的不知道你有没有理解,一会代码展示的时候,你就会一目了然,代码很简单。在template模式中,采用的是继承的方式实现上述的内容。template模式的结构图:对于template模式的实现就是运用...
阅读全文
摘要:作用:定义了算法家族,分别封装起来,让他们之间可以互相替换,此模式让算法的变化,不会影响到使用算法的客户。
UML图:
Strategy模式将逻辑(算法)封装到一个类(Context)里面,通过组合的方式将具体算法的实现在组合对象中实现,再通过委托的方式将抽象接口的实现委托给组合对象实现将算法的逻辑抽象接口(DoAction)封装到一个类中(Context),再通过委托的方式将具体的算法实现委托给...
阅读全文
摘要:Builder模式要解决的问题是,当我们要创建很复杂的对象时,有时候需要将复杂对象的创建过程和这个对象的表示分离开来。由于在每一步的构造过程中可以映入不同参数,所以步骤相同但是最后的对象却不一样。也就是说将产品的内部表象和产品的生成过程分割开来,从而使一个建造过程生成具有不同的内部表象的产品对象。 Builder模式的关键在于在创建一个复杂对象时,其组合过程往往涉及复杂的处理,同时,这...
阅读全文
摘要:1 #include 2 using namespace std; 3 class A 4 { 5 public: 6 void sayHi(){ 7 coutsayHi();
14 p = NULL;
15 p->sayHi();
16 } 以上输出:(因为A::sayHi()并未使用this指针。因此尽管this指针是NULL,只要不...
阅读全文
摘要:1 /*堆排序(大顶堆) 2011.9.14*/ 2 3 #include 4 #include 5 using namespace std; 6 7 void HeapAdjust(int *a,int i,int size) //调整堆 8 { 9 int lchild=2*i; //i的左孩子节点序号 10 int rchild...
阅读全文
摘要:1 // 主程序 (.cpp文件) 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include "BobbleSort.h" 8 #include "QuickSort.h" 9 #include "HeapSort.h" 10 11 int main() 12 {
...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 struct IA 5 { 6 virtual void funInIA() = 0; 7 }; 8 9 struct IB
10 {
11 virtual void funInIB() = 0;
12 };
13 14 struct C : public IA, publi...
阅读全文
摘要:Declaration Following is the declaration for sprintf() function.int sprintf(char *str, const char *format, ...)
Example
The following example shows the usage of sprintf() function.
#include #include ...
阅读全文
摘要:1: #include 2: int system(const char *command); 3: 4: while (something) { 5: int ret = system("foo"); 6: if (WIFSIGNALED(ret) && ...
阅读全文
摘要:Source code: 1: #include 2: void myStartupFun (void) __attribute__ ((constructor)); 3: void myCleanupFun (void) __attribute__ ((destructor)); 4: 5: /...
阅读全文
摘要:Source file: 1: #define __USE_GNU //import! 2: #include 3: #include 4: void getFuncNameByAddr(void *this_fn, void *call_site) { 5: Dl_info DlInfo...
阅读全文
摘要:myFun.h 1: #include 2: 3: void __cyg_profile_func_enter(void *this_fn, void *call_site) 4: __attribute__((no_instrument_function)); 5: void _...
阅读全文
摘要:1: int save_out = dup(fileno(stdout));//backup stdout 2: int out = open("cout.log", O_RDWR|O_CREAT|O_APPEND, 0600); 3: int nRet; 4: fflush(stdout); 5...
阅读全文
摘要:转自:http://blog.chinaunix.net/uid-23670869-id-2943505.html
Linux中常常会使用到cut命令来分割字符串,下面说明下cut命令参数的使用:
-d 指定分隔符,如:按照“:”分割,-d:
-c 提取第n个字节,如:-c5,表示提取每行的第5个字节,-c5-14,表示提取每行的第5-14个字节,-c1,5,14,表示提取第1、5、14个字节。...
阅读全文
摘要:1: #include 2: #include 3: #include 4: #include 5: 6: struct S { 7: std::string firstname; 8: std::string secondname; ...
阅读全文
摘要:说明:此博文转载之http://blog.sina.com.cn/s/blog_69c189bf0100mkeu.html
类所占内存的大小是由成员变量(静态变量除外)决定的,成员函数(这是笼统的说,后面会细说)是不计算在内的。
摘抄部分:
成员函数还是以一般的函数一样的存在。a.fun()是通过fun(a.this)来调用的。所谓成员函数只是在名义上是类里的。其实成员函数的大小不在类的对象里面,...
阅读全文
摘要:错误类型:
找不到 'libboost_regex-vc80-mt-sgd-1_41.lib' 你自己的库文件里只有libboost_regex-vc80-mt-gd-1_41.lib 别人的解释:Difference is clearly described in Boost docs - "mt-sgd" means "debug, statically linked runtime ...
阅读全文