Thread: Clear little database

  1. #1
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133

    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 01024i++ )
    {

        
    string Database ] = '\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.
    Last edited by Yuri; 02-12-2006 at 09:09 AM.

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    if Database is an array of POD (plain-old-data) types, such as char* then you can use memset
    Code:
    memset(Database,0,1024);

  3. #3
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    Sorry, I edited my thread, it's a C++ string.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Code:
    Database.clear();

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    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.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. literature database: help with planning
    By officedog in forum C++ Programming
    Replies: 1
    Last Post: 01-23-2009, 12:34 PM
  2. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 01:09 PM
  3. Replies: 10
    Last Post: 05-18-2006, 11:23 PM
  4. Developing database management software
    By jdm in forum C++ Programming
    Replies: 4
    Last Post: 06-15-2004, 04:06 PM
  5. Making a Simple Database System
    By Speedy5 in forum C++ Programming
    Replies: 1
    Last Post: 03-14-2003, 10:17 PM