pascal→→c++常用基礎小知識

來源:互聯網
上載者:User

 

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

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.