CºêµÄÓ÷¨
Ç°¼¸Ìì²Î¼Óij¹«Ë¾µÄ±ÊÊÔ£¬ÓÐÒ»µÀÌâÊÇÓô¿CʵÏÖÒ»¸ö·ºÐͺ¯Êý¡£ÓôÃÆÁ˺þÃÓÃC++Ä£°åʵÏÖÁË¡£
ºêÓÐÈçϵÄÌص㣺
1.ÓëconstÏà±È£¬ºêÊÇÔÚÔ¤±àÒëµÄʱºòÍê³ÉµÄ
2.define Ö»×ö¼òµ¥µÄÌæ»»£¬²»×öÀàÐÍ°²È«¼ì²é
3.ʹÓò»µ±»áÒýÆðºÜ¶àÎÊÌâ
ºêµÄÓ÷¨£º
1.¼òµ¥µÄºê¶¨Òå
#define MAX 1024
2.ºê¶¨Ò幦ÄÜ¿é
#define MAX(a,b) (a)>(b)?(a):(b) //±È½Ï´óСµÄºê
3¶¨Ò庯ÊýʵÏÖ·ºÐÍ
#define SORT(Type) void Buble_sort(Type a[],int len) { \
bool is_swap=true;\
for(int i=0;i<len&&is_swap;++i)\
{\
is_swap = false;\
for(int j=0;j<len-i;++j)\
{\
if(a[j]>a[j+1])\
{\
Type t;\
t=a[j];\
a[j+1] = a[j];\
a[j]=t;\
is_swap = true;\
}\
}\
}\
}
SORT(int);
SORT(double);
SORT(float);
SORT(unsigned int);
4.¶¨ÒåÀà
#define _DECL_class(name, element )\
class df_##nm\
{\
protected:\
element *pData;\
int num;\
\
void _resize(int n);\
\
public:\
nm( ){};\
\
int Count() const { return num; }\
\};
_DECL_class( cls_example, int );
Ïà¹ØÎĵµ£º
ÐÅÔë±È( S N )ÊÇÖ¸´«ÊäÐźŵÄƽ¾ù¹¦ÂÊÓë¼ÓÐÔÔëÉùµÄƽ¾ù¹¦ÂÊÖ®±È¡£
ÔØÔë±È(C N )Ö¸ÒѾµ÷ÖƵÄÐźŵÄƽ¾ù¹¦ÂÊÓë¼ÓÐÔÔëÉùµÄƽ¾ù¹¦ÂÊÖ®±È¡£
ËüÃÇͨ³£¶¼ÒÔ¶ÔÊýµÄ·½Ê½À´¼ÆË㣬µ¥Î»ÎªdB¡£
ÐÅÔë±ÈÓëÔØÔë±ÈÇø±ðÔÚÓÚ£¬ÔØÔë±ÈÖÐÒѵ÷ÐźŵŦÂÊ°üÀ¨ÁË´«ÊäÐźŵŦÂʺ͵÷ÖÆÔز¨µÄ¹¦ÂÊ£¬¶øÐÅÔë±ÈÖнö°üÀ¨´«ÊäÐźŵŦÂÊ£¬Á½ÕßÖ®¼äÏà²îÒ ......
ÈÝÒ×´íÎóµÄʹÓÃÖ¸Õë:
void GetMemory(char *p, int num)
{
p = (char *)malloc(sizeof(char) * num);
}
void Test(void)
{
char *str = NULL;
GetMemory(str, 100); // str ÈÔȻΪ NULL
strcpy(str, "hello"); // ÔËÐдíÎó
}
벡³öÔÚº¯ÊýGetMemory ÖС£±àÒëÆ÷×ÜÊÇÒ ......
¸ñʽ: echo "\033[×Ö±³¾°ÑÕÉ«;×ÖÌåÑÕÉ«m×Ö·û´®\033[0m"
ÀýÈç:
echo "\033[41;36m something here \033[0m"
ÆäÖÐ41µÄλÖôú±íµ×É«, 36µÄλÖÃÊÇ´ú±í×ÖµÄÑÕÉ«
ÄÇЩascii code ÊǶÔÑÕÉ«µ÷ÓõÄʼĩ.
\033[ ; m …… \033[0m
×Ö±³¾°ÑÕÉ«·¶Î§:40----49
40:ºÚ
41:Éîºì
42:ÂÌ
43:»ÆÉ«
44:À¶É«
45:×ÏÉ«
4 ......
³£Óú궨Òå
1¡¢·ÀÖ¹Ò»¸öÍ·Îļþ±»Öظ´°üº¬
#ifndef COMDEF_H
#define COMDEF_H
//Í·ÎļþÄÚÈÝ
#endif
2¡¢ÖØж¨ÒåһЩÀàÐÍ£¬·ÀÖ¹ÓÉÓÚ¸÷ÖÖƽ̨ºÍ±àÒëÆ÷µÄ²»Í¬£¬¶ø²úÉúµÄÀàÐÍ×Ö½ÚÊý²îÒ죬·½±ãÒÆÖ²¡£
typedef unsigned char boolean; /* Boolean v ......
//ÒÔϳÌÐòÊÇʵÏÖСдת´óд³ÌÐò
#include<stdio.h>
void to_upper(char *str)
{
for(;*str !='\0';str++)
{
if(unsigned(*str-'a')<='z'-'a')
*str-='a'-'A';//Ð ......