Possible Duplicate:
Is there memset() that accepts integers larger than char?
As it can be seen in memset’s declaration:
void * memset ( void * ptr, int value, size_t num );
Is there any way to use this memset function (or another function included in STL library) so that you can set memory to a long long type value?
I use this to initialize an array of long longs with a large value.
I have to say that I’ve “solved” this problem by simply iterating through each value of the array and setting it to the desired value.
memsetonly uses one byte of the value passed in and does bytewise initialization. If you want to initialize along longarray with a particular value, just usestd::fillorstd::fill_nand let your library and compiler optimize it as they can (partial loop unrolling etc).Another canonical C++ way is to just use
vectorand let its constructor do the work for you:std::vector<long long> foo(length_of_array, 12345678901234LL);