Search code examples
vectorcallocshorthand

How to shorten std::vector?


Instead of doing this for calloc:

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

I have this at the top of my C++ file:

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

so I can more easily write this:

TCHAR *sText = tcalloc(1024);

Now, how do I do a shorthand for my std::vector statement? This is my code:

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


Solution

  • maybe

    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;   
        ...
    }