如何缩短std :: vector?

时间:2014-02-26 12:24:20

标签: vector calloc shorthand

而不是为calloc执行此操作:

TCHAR *sText = (TCHAR *) calloc(1024, sizeof(TCHAR));

我把它放在我的C ++文件的顶部:

#define tcalloc(nCharacters) (TCHAR*)calloc(nCharacters,sizeof(TCHAR))

所以我可以更轻松地写下这个:

TCHAR *sText = tcalloc(1024);

现在,我如何为我的std :: vector语句做简写?这是我的代码:

std::vector <TCHAR>sText(1024,0);

1 个答案:

答案 0 :(得分:1)

也许

typedef std::vector<TCHAR> tcVec;
#define init_1k_charVector tcVec(1024,0)
int main(int, char**)
{
    tcVec sText(1024,0);
    tcVec sText2 = init_1k_charVector;   
    ...
}