November 29, 2001

Always Use the Collection Name when Using Request Object

In ASP, Request object has five collections: QueryString, Form, Cookies, ClientCertificate, and ServerVariables. When you want to access information in one of these collections, you have the choice of writing the name of the variable directly after Request object without specifying the collection name in which the variable is stored.

Create Flexible Cross-tab Queries without Using Temporary Tables

It’s very easy to create cross-tab queries in SQL. In the SELECT statement of a query, most databases allow you to use an expression with an aggregate function, not only a field name. In access use this syntax: SELECT Sum(Iif(District=’US’, Sales, 0)) as SalesUS,Sum(Iif(District=’Europe’, Sales, 0)) as SalesEurope _ FROM

Packing an XML Parser with a Java Application

You can pack the XML Parser along with the Java Application you are shipping. The following steps show how to do this. I used the Apache’s Xerces and Xalan parsers for XML and XSLT as an example. Un-Jar the xerces.jar and xalan.jar into a temporary directory. Copy your Java application

Detecting the Actual Size of a Memory Block Allocated by new

The following trick isn’t portable. Furthermore, even implementations that currently support it do not guarantee to support it in their future releases. Still, it can teach you a few things about the inner-workings of your heap manager. When allocating arrays dynamically using new, most implementations store the array’s size in

Use enum Types in switch Statements

Certain compiler and code analyzers can detect a missing enumerator in a switch statement. Consider: enum Seasons{ Winter, Spring, Summer, Fall};switch (s){case Winter: wearCoat(); break;case Spring: pruneGarden(); break;case Summer: goSwimming(); break; // forgot to include a case for ‘Fall’} The programmer listed only three cases in the switch statement, omitting

Concatenating Variables

If you need to concatenate variables of different types to form a string, use a stringstream object. The header contains the declarations of the stringstream family of classes. Using its overloaded > operator: #include void concat(std::string &result){ long x = 1000; double y = 5.5.; std::stringstream s; s

Reading a String from the Standard Input

There are two methods of reading a string from the standard input. The first one uses getline(), as in the following example: std::string name;getline(cin, name); // option #1 The second method uses cin: cin >> name; // option #2 The two methods aren’t interchangeable, though. getline() reads a line of

Setting a New Handler

The function std::set_new_handler() installs a function to be called when the global operator new or the global operator new[] fail. By default, operator new throws an exception of type std::bad_alloc in the event of a failure (note that Visual C++ still retains the traditional version of new, which doesn’t throw

Floating Point Types

C++ defines three floating points datatypes: float, double and long double. Some existing implementations support only two (and in some cases only one) of these three. On such implementations, double and long double are interchangeable. Your implementation documents the floating point datatypes it supports and their characteristics in the header

No more posts to show