Compaq C++ User Documentation


Compaq C++

Compaq C++
Class Library Reference Manual

Previous Contents Index

Chapter 5
Messages Package

The Messages package provides a way to retrieve messages stored in a catalog or file that is separate from your program. It consists of a single class, Messages , that retrieves the text of a message.

A message set number is a number specified in the message catalog source file with a $set n line, ranging from 1 to NL_SETMAX, as defined in nl_types.h . To process the message catalog source file, use the gencat command. For more information see the gencat (1int) reference page.

Messages class

Retrieves message text for a message number.

Header File

#include <messages.hxx>

Alternative Header



class Messages 
   Messages(const char *filename_arg, int set_arg = 0, 
        const char *default_file_location_arg = (const char *)(NULL)); 
   const char *text(int msg_arg, const char *fallback_text_arg, 
         int set_arg = 0); 

Exception Handling

If the message file cannot be opened or closed, the system prints one of the following error messages on cerr (as appropriate):
Cannot open message catalog " catalog name " -- check NLSPATH
Cannot close message catalog " catalog name "

Constructors and Destructors

Messages(const char *filename_arg, int set_arg, const char *default_file_location_arg)

Constructs a Messages object. The filename_arg argument specifies the file name of the message catalog. The set_arg argument specifies the message number to set; a value of 0 specifies that the default setting (NL_SETD as defined in nl_types.h ) be used. The default_file_location_arg argument specifies the default location of filename_arg.


Deletes a Messages object.

Member Function

const char *text(int msg_arg, const char *fallback_text_arg, int set_arg)

Returns the text of the message specified by the msg_arg argument. The fallback_text_arg argument indicates the text to return if the message cannot be found. The set_arg argument specifies the message set number; a value of 0 causes the system to use the set number provided to the constructor.


The following is a sample message source file:

$ messages_example.msf   Messages example -- Digital UNIX message catalog 
$ set 1 EXAMPLE_SET 
1 This is an example error message 
$ End of messages_example.msf 

Entering the following gencat command compiles this file:

$ gencat message_example.msf 

The following program retrieves the sample error message:

#include <iostream.hxx> 
#include <messages.hxx> 
const char *message_file_name = "messages_example"; 
const char *message_file_location = ""; 
int message_set_example = 1; 
Messages m_example (message_file_name, message_set_example, 
int main() 
    cout << 
        "text of example message 1: " << 
        m_example.text(1, "fallback message 1") << 
    cout << 
        "text of example message 2: " << 
        m_example.text(2, "fallback message 2") << 
    return EXIT_SUCCESS; 

Executing the program without compiling the message source file displays the following fallback messages:

text of example message 1: fallback message 1 
text of example message 2: fallback message 2 

After compiling the message source file and setting the NLSPATH environment variable, executing the program retrieves the text of the error message and displays the second fallback message:

text of example message 1: This is an example error message 
text of example message 2: fallback message 2 

Previous Next Contents Index
About PDF files: The PDF files on this site can be read online or printed using Adobe® Acrobat® Reader. If you do not have this software on your system, you may download it from Adobe's website.
Privacy statement Using this site means you accept its terms C++ support
© 2008 Hewlett-Packard Development Company, L.P.