WebSphere Message Service Client for C/C++, Version 2.0.2 Operating Systems: AIX, Linux, Solaris, Windows

String objects in C++

In the C++ API, a String object encapsulates a string. When called, certain methods accept a String object as a parameter or return a String object.

A String object can encapsulate a null terminated character array. Alternatively, a String object can encapsulate a byte array with embedded null characters, where the byte array might or might not be, null terminated. Therefore, when an application creates a String object from a byte array, the application must specify the length of the array. The following code fragment creates both types of String object:

#include <xms.hpp>

using namespace std;

int main(int argc, char *argv[])
{
  xms::String strA("Normal character string");
  xms::String strB("This\0string\0contains\0nulls", 26);

  // The overloaded assignment operator can be used to create
  // a String object from a null terminated character array.

  xms::String strC = "Another character string";

  // Other code here

  return(0);
}

To make it easier to create and manipulate String objects, certain operators and constructors are overloaded on the String class. If an application calls a method that requires a String object as an input parameter, it is not necessary to create the String object first. The application can pass a null terminated character array to the method as a parameter, and XMS automatically creates a String object on the stack.

In addition, the String class encapsulates methods to create and manipulate String objects. For the definitions of these methods, see String.


Concept topic

Terms of Use | Rate this page

Last updated: 24 May 2011

(C) Copyright IBM Corporation 2005, 2011. All Rights Reserved.