c/c++
文章平均质量分 64
xingdebocqyz
这个作者很懒,什么都没留下…
展开
-
c++中的extern "C"
1.什么时候用1) c++要引用c编译的函数或者变量2 )c要引用c++编译的函数或者变量 2.为什么要用 两种语言对函数的编译方式差异:c中仅将函数名作为特征符,而c++为了实现重载,将函数名+参数列表作为特征符。比如函数 int f(int a);C中特征符类似_fC++中特征符类似_f_int所以两种语言在互相引用的时候,要通过extern "C"原创 2013-09-12 01:08:47 · 620 阅读 · 0 评论 -
C/C++中“#”和“##”的作用和用法
FROM:http://www.2cto.com/kf/201503/381187.html在C/C++的宏中,”#”的功能是将其后面的宏参数进行字符串化操作(Stringfication),简单说就是在对它所引用的宏变量通过替换后在其左右各加上一个双引号。而”##”被称为连接符(concatenator),用来将两个子串Token连接为一个Token。注意这里连接的对象是Token就转载 2015-09-15 20:52:50 · 444 阅读 · 0 评论 -
strtok的用法
#include #include using namespace std;int main(){ char sentence[]="This is a sentence with 7 tokens"; cout<<"The string to be tokenized is:\n"<<sentence<<"\n\nThe tokens are:\n\n"; char *tokenPt转载 2013-10-23 02:06:43 · 511 阅读 · 0 评论 -
伪造ip包代码
http://blog.csdn.net/flash9008/article/details/5811298转载 2013-10-07 02:00:04 · 695 阅读 · 0 评论 -
远指针FAR/近指针NEAR/_STDCALL/_CDECL
今天看到inet_ntoa函数的原型,这个返回类型实在是没见过:char FAR* PASCAL FAR inet_ntoa(struct in_addr in);搜索了一下:1.关于FAR:(来自http://blog.csdn.net/sphone89/article/details/7184976)FAR 是16位系统时候的概念了,代表远指针的意思。近指针是1转载 2013-10-07 00:18:38 · 802 阅读 · 0 评论 -
send()函数的理解和recv()函数
http://no001.blog.51cto.com/1142339/530815转载 2013-09-19 01:47:00 · 676 阅读 · 0 评论 -
快速排序
#include "iostream" #include "vector" using namespace std; void qSort(int a[], int l,int r){ if(l >= r) return; int i = l,j = r,key = a[l]; while(i < j){ while(i = key) j--;转载 2013-09-18 19:28:41 · 548 阅读 · 0 评论 -
Windows线程+进程通信
http://www.cnblogs.com/itech/archive/2010/06/29/1767311.html转载 2013-09-18 19:14:36 · 515 阅读 · 0 评论 -
数组排列/全排列(data数组没有重复元素)
思想:依次生成以data[0]开头的所有排列,data[1]开头的所有排列...#include "iostream"#include "iterator"#include "algorithm"using namespace std;int data[5] = {1,2,3,4,5};void perm(int index[],int n, int k) {转载 2013-09-18 18:33:32 · 635 阅读 · 0 评论 -
[西山居笔试]分别写一个宏和函数来获取元素个数 如count(a) 会得到a数组元素个数
#include "iostream" using namespace std;#define COUNT(arr) (sizeof(arr) / sizeof(arr[0])) templateint count(T &arr){ return sizeof(arr) / sizeof(arr[0]);}int main() { int a[101]原创 2013-09-19 01:15:31 · 1861 阅读 · 0 评论 -
[迅雷笔试题]从1....n中随机输出m个不重复的数
思想:先以m/n的概率判断第一个数出不出现;如果出现,那么以(m-1)/(n-1)的概率判断下一个数出不出现;若不出现,那么以m/n-1的概率判断下一个数出不出现,等于如果前面的数不出现的话加大后面的数的出现概率。#include "iostream"#include "ctime"#include "cstdlib"using namespace std;void knu转载 2013-09-18 18:47:02 · 956 阅读 · 0 评论 -
STL迭代器简介
原文网址:http://www.cppblog.com/The-Moment/archive/2009/06/18/88023.html标准模板库(The Standard Template Library, STL)定义了五种迭代器。下面的图表画出了这几种: input output \ /转载 2013-10-03 16:34:28 · 360 阅读 · 0 评论 -
STL:如何释放vector占用的内存
(一道百度面试题)C++ STL中vector的相关问题,调用clear时,内部是如何具体实现的?若想将其内存释放,该如何操作? 假设有一个vector x(100);这样首先会申请(100*sizeof(int))的内存大小。调用clear函数仅仅是将数据清除,而申请的内存还是存在的,并没有释放掉。可以调用下面的语句进行释放:{ vector t; t.s原创 2013-09-18 14:05:03 · 1425 阅读 · 0 评论 -
函数指针例子
一个最简单的函数指针定义如下:Void (*funcPtr) (); //funcptr是一个函数指针,它指向的函数没有参数,返回值为void非常复杂的函数指针定义:1. Void * (* ( * fp1)(int))[10];解析:Void * X[10];è这是一个有10个void*类型的元素的数组。 X=* ( * fp1)(i转载 2013-10-02 22:50:35 · 613 阅读 · 0 评论 -
c++ delete[]:怎么知道需要释放的空间大小
今天想到了这个问题,开始以为和数组一样,要在同一个作用域内才能知道释放多少空间:#include "iostream"using namespace std;class A{ int static i;public: A(){} ~A(){cout<<"释放第"<<++i<<"个对象"<<endl;};};int A::i = 0;int main(原创 2013-10-02 13:49:45 · 2783 阅读 · 0 评论 -
C++ 对象内存布局
好文要记下来http://blog.csdn.net/haoel/article/details/1948051转载 2013-09-10 18:12:07 · 501 阅读 · 0 评论 -
类型转换中的有符号转换与无符号转换
int main(){ char c1 = 0x08; char c2 = 0x80; unsigned char uc1 = 0x08; unsigned char uc2 = 0x80; int int_c1 = (int)c1; int int_c2 = (int)c2; int int_uc1 = (int)uc1; int int_uc2 = (int)u原创 2013-09-11 22:11:09 · 517 阅读 · 0 评论 -
给一个无符号数前置减号,结果仍为无符号
unsigned int x = 10;-x;warning C4146: unary minus operator applied to unsigned type, result still unsigned原创 2015-09-18 09:43:32 · 501 阅读 · 0 评论