-
Clear little database
Hi.
I was wondering if there is another way or better way to clear my database, I had this but I would like another way, to learn from.
PHP Code:
for ( int i = 0; i < 1024; i++ )
{
string Database [ i ] = '\0';
}
Why I am making such big deal is because I am still learning and I saw something like Array [ 0 ] = { 0 }; or something simular, what does that do? Could that be usefull?
Thanks, Yuri.
-
if Database is an array of POD (plain-old-data) types, such as char* then you can use memset
Code:
memset(Database,0,1024);
-
Sorry, I edited my thread, it's a C++ string.
-
-
you can use generic template functions like these that work on any datatype that can be (safely) constructed without arguments:
Code:
template <class T>
inline
void
init(T & value)
{
value = T();
}
template <class I>
void
init(I begin, I end)
{
while(begin != end)
{
init(*begin++);
}
}
template <class I>
void
init(I begin, unsigned n)
{
while(n)
{
init(*begin++);
n--;
}
}
you could even optimize it further for POD's using some sort of template specialization scheme.