pascal→→c++常用基础小知识

 

d mod,/,div  ----c? % /

d round()---c?

d label---c?c中不用声明label 直接用就行了,不须声明!!

d and or not --c?算术符& | ! 逻辑运算符&& || !

d byte(pointer(stru.bitdata+stru.pos)^)----c?*((unsigned char*)(stru.bitdata+stru.pos))

  F_src :pointer      void * F_src
d,byte(F_src^);------c?*( (byte*)(F_src) )

定义类型指针:
d:
type
  Tcardpointer=^cardinal;
c:
typedef
  unsigned int *Tcardpointer;

1,c 在.h头文件声明函数参数带默认值,在.cpp实现文件就不用在带默认值了!

true=-1;false=0


2,c .h文件前向声明的变量在.cpp中还要在声明一遍,并且初始化是在.cpp文件中的(true=1,false=0)

3,c if (条件)
       (语句);    
    else
       (语句);


  c if (条件)
    {
     (语句);      
    }
    else
    {
     (语句);      
    };
注意分号···········

4,c 数组类型的结构,若作为全局变量必须在.h文件extern声明,再在.cpp文件初始化
例如:
.h:
typedef struct Tdepth
{
    int spriteindex; // -1:主场景depth/obj关系 ;>=0:子动画depth/obj关系
    unsigned short id;
    unsigned short objid;
};
extern Tdepth *depths;
extern int depths_len;

.cpp:
Tdepth *depths=NULL;
int depths_len=0;

5,d setlength(tbitarray,0);
  c free(tbitarray.data);
    tbitarray.length=0;
6,d  var CCdis_proc:procedure(F_index1,F_index2:integer);
  c  extern (void*)CCdis_proc(int F_index1,int F_index2 );
  C  extern  void *CCdis_proc(int F_index1,int F_index2 );

7,d ord('F');------c? 'F';
8,c---char*  "aaaaaaaaaa"; char 'a';

9,d: repeat ...until(条件);
  先执行语句后判断有条件,直到条件为真时结束循环;注意条件为真时结束!!
  d:while(条件)do begin ...end;
  先判断条件再执行语句,直到条件为假时结束循环;

  c:?do {...}while(条件);
  先执行语句再判断条件,直到条件为假时结束循环;
  while{...};与d的while.. do..一样;
 
10,d 内嵌函数在c中怎么处理?用namespace 处理,如下:

命名空间能解决内嵌函数的问题:
命名空间定义:在.h文件里;
namespace Outer{
          int i;
          namespace Inner{
                    void f(){i++;}//命名空间Inner的内部成员f()的定义 ;其中i为Outer::i
                    int i;
                    void g(){i++;}//命名空间Inner的内部成员g()的定义 ;其中i为Inner::i
                    void h();//命名空间Inner的内部成员h()的声明
                    };
          void f();
          namespace Inner2;//错误,子命名空间不能声明只能定义
          };
void Outer::f(){i--;}//命名空间Outer的内部成员f()的外部定义 ;
void Outer::Inner::h(){i--;}//命名空间Inner的内部成员h()的外部定义;

命名空间的使用:在.cpp文件里;
using namespace Outer;
int main
{
...
Outer::i=0;
OUter::f();            //i=-1;

Outer::Inner::i:=1;
Outer::Inner::g();     //i=2;
...
};
//以上的Outer::可省;但Inner::不可省;
★★★namespace 的内部成员函数的定义都放在.cpp文件;



.h文件里
x.h:
namespace Outer{
      class myclass
      {
             public:
               void f();
             private:
               int i;
      };
};

y.h:
namespace Inner{
      calss myclass
      {
             public:
               void f();
             private:
               int i;
      };
};

 

.cpp文件里
#include "x.h"
#include "y.h"
int z::f()
{
Outer::myclass x;
Inner::myclass y;

   x.f();
   y.f();
};


11,数组 d a:array[0..l] of array [0..m] of array[0..n] of integer;
        c integer a[l][m][n];  m行n列
        

12,d,   vcaption:=vcaption div trunc( exp( ln(2)*(8-F_Ccaption) ) );
         vcaption:=vcaption mod trunc( exp( ln(2)*(8-F_top+1) ) );

    c,  //vcaption=vcaption / (2^(8-F_caption));
  vcaption=(unsigned char)(vcaption / pow(2, 8-F_caption));
  //vcaption=vcaption % (2^(8-F_top+1));
  vcaption=(unsigned char)(vcaption % (int)pow(2,(8-F_top+1)));

13,c:定义宏:
#define 宏名字  要被代替的名字;
使用的时间使用“宏名字”就可以了。

14,在shape_record_opt,shape_record_pos_proc有个initialization未处理!这样的情况只要把所有的变量初始化就可以;

15,d 字符串'audio\'---------------c "\audio\\"
16,d sysutils format() -------------------------c "stdio.h"sprintf();
  string s;
  s:=format(' --resample %d -b %d ',11, 16);
  showmessage(s);                               --resample 11 -b 16            

  char s[255]="";
  sprintf(s," --resample %d -b %s ",11,"16");   --resample 11 -b 16
  sprintf(s," --resample %x -b %d ",11,16);     --resample b -b 16
  cout<<s;
  cin.get();
注意:%的位置那些字符代表显示出的形式,有s,d,x,0x.....

··············································
DOS命令:
cd\
C:\>

cd\mingw
C:\Mingw>

cd\mingw\bin
C:\mingw\bin>


C:\Mingw\bin>c++ -c c:\new0322\文件名;(编译)
C:\Mingw\bin>dir ddcc.* 或  dir ddcc.o
C:\Mingw\bin>c++ *.o c:\*.cpp -o c:\aa  (全部连到一起编译)

··············································


stdio.h
int __cdecl sprintf (char*, const char*, ...);
e.g:
int main {
int a=1234;
char str[255]="";
sprintf(str,"%d",a);
cout<<str;
cin.get();
};

iostream.h
cout
cin

string.h
strcat
strcpy
strcmp
memcpy

 

 

转载于:https://www.cnblogs.com/qdlgx/archive/2009/04/11/1433802.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值