posts - 9,comments - 21,trackbacks - 0
re: cin之于char[]和string 蕃豆仁 2006-04-12 15:19
一直以为string = char[],看来在某些情况下会出意外?
还是我的理解本来就片面?
typedef和#define 蕃豆仁 2006-04-03 14:47
#include <iostream>
//typedef和#define
typedef int prablint;
#define prablchar char

typedef int* prabl_int_p;
#define prabl_char_p char*


int main()
{
using namespace std;
prablint a = 0;
prablchar b = 'a';

prabl_int_p c,d;
prabl_char_p e,f;

cout << sizeof(a) << endl;
cout << sizeof(int) << endl;
cout << sizeof(b) << endl;
cout << sizeof(char) << endl;
cout << sizeof(c) << "," << sizeof(int*) << endl;
cout << sizeof(d) << "," << sizeof(int*) << endl;

cout << sizeof(e) << "," << sizeof(char*) << endl;
cout << sizeof(f) << "," << sizeof(char*) << endl; //f是char型,不是char*。所以用typedef是更安全的

system("PAUSE");
return 0;
}