April 3, 2001

The Lifetime of Temporary Objects

Temporary objects, or unnamed objects, are created as a result of expressions requiring a temporary object or when the user instantiates them explicitly. If the temporary object is not bound to a reference and it isn’t used as an initializer of a named object, it is destroyed at the end

Converting a Hexadecimal String to int

Suppose you need to convert a string containing a hexadecimal value to int. Although you can use a std::stringstream object for this purpose, it’s worth noting that good old C stdio can perform this conversion just as well. The sscanf() function takes a string containing the hexadecimal value, a format

Detecting end-of-file in Input Streams

std::istream and std::ifstream objects define the eof() member function which returns true when the stream object has reached the end of a file. Note that at least one read operation must be performed to raise the eof() flag. Thus, opening an empty file or positioning the file pointer at a

Nested Comments

Standard C and C++ don’t allow comments to be nested. Thus, the following code snippet is ill-formed because it has one /**/ comment nested within another pair of comments: /*int func() /* a nested comment */{

Detecting How Many Files a Process Can Open Simultaneously

All implementations impose a limit on the number of files that a process can open simultaneously. This limit depends on various factors such as the process’ privileges, the number of open files that other processes currently use, and the system’s resources. The constant FOPEN_MAX which is defined in ( in

Determine if an Error Has Occured During Object Construction

This can be achieved in java by throwing an exception from your Constructor. Since Constructors cannot return a value, this is the only way you can achieve error handling. Class MyCLass{ private int x; File file; MyClass() throws MyException{ x = 10; try{ file = new File(

How to Read NT System Properties

A direct method or class that will allow you to read NT system properties does not exist. However, it can be done as follows: Write a simple batch command file with a dos command to echo the value of the environment variable to a text file, then read the content

Customizing an Editable JComboBox

A previous tip explained how to change the appearance of the ‘list selection’ cells of a JComboBox by setting the attributes of the JComboBox object’s ListCellRenderer.However, the ListCellRenderer controls the item area for a non-editable JcomboBox. A ComboBoxEditor controls the item area for an editable JcomboBox (which, in turn, contains

How to Use Maps Effectively

The java.util.Map interface is the root interface of the map hierarchy. Interestingly, it doesn’t extend the familiar java.util.Collection interface. It facilitates storage, retrieval, and manipulation of key-value pairs.The popular implementations of Map are java.util.HashMap andjava.util.TreeMap. The HashMap facilitates easy insertion, deletion, and retrieval of elements. On the other hand, TreeMap

No more posts to show