Subscribe to RSS Subscribe to Comments

mogri : network

Class initialization: Constructor

It has been a long time since I worked on C++ so let’s start collecting all the questions that I have…

Rect::Rect( int x1, int y1, int x2, int y2 ) :
_topleft( x1, y1 ), _bottomright( x2, y2 ) {}

Why not this?

Rect::Rect( int x1, int y1, int x2, int y2 ) :
{
_topleft( x1, y1 );
_bottomright( x2, y2 );
}

CSV Writer

How do you write CSV file using C#? Although there are many ways to accomplish the task, I’ve found using Hashtable/Dictionary object helps a lot writing a generic CSV Writer code.

A good thing about using Hashtable/Dictionary object is that you can align each value with the column name to make sure every column gets the right value. Of course, using an array would also work, but one can make a silly mistake by misusing index number. That is where Hashtable/Dictionary object plays an important role by using associative array structure (In Perl, hashtable is also called associative array) with key as the column header.

Reading a text file without locking the file.

Often time, we want to read a text file that other process is writing onto. In C#, FileStream attempts to lock the file by default. This is not desirable if there is a process put a lock on the file already; FileStream won’t be able to read the file. Here is a simple code to read a text file while other process is writing onto it.


FileStream fs = null;
StreamReader sr = null;
try {
    fs = new FileStream(string_file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
    sr = new StreamReader(fs);
} catch (FileNotFoundException e){
    // exception handling
}

writing c++…

I am attempting to write my first c++ code in years. I expect a lot of ramp-up time.

Let’s see how it goes.

Based on Fluidity©2006-2007 mogri.net | Theme Redesigned by Kaushal Sheth Sponsored by Web Hosting Bluebook