Google

C++ Portable Types Library (PTypes) Version 1.7


Top: Basic types: string: Operators

#include <ptypes.h>

// assignment
string& string::operator=  (const char* sc);
string& string::operator=  (char c);
string& string::operator=  (const string& s);
void    assign(string& s, const char* buf, int len);

// concatenation
string& string::operator+= (const char* sc);
string& string::operator+= (char c);
string& string::operator+= (const string& s);
string  string::operator+  (const char* sc) const;
string  string::operator+  (char c) const;
string  string::operator+  (const string& s) const;
friend  string operator+   (const char* sc, const string& s);
friend  string operator+   (char c, const string& s);

// comparison
bool    string::operator== (const char* sc) const;
bool    string::operator== (char) const;
bool    string::operator== (const string&) const;
bool    string::operator!= (const char* sc) const;
bool    string::operator!= (char c) const;
bool    string::operator!= (const string& s) const;

// indexed character access, 0-based
char&   string::operator[] (int I);

The string class defines the following binary operators: assignment (=), concatenation (+), concatenation with assignment (+=) and comparison (==, !=). At least one of the operands (either left or right) must be of type string. Another operand can be one of the following: char, char* or string.

Indexed access operator allows to store or retrieve a value of an individual character. The index is 0-based. When compiled with either DEBUG or _DEBUG conditional symbol, bounds checking is performed for the indexed access; if the index is out of bounds (i.e. less than 0 or equals to or greater than the length of the string), an unrecoverable error is raised. The non-debugging version of the library never checks for index overlfows, thus making your program somewhat faster but less safe.

Examples

string s1 = "abc", s2 = 'd', s3;

s3 = s1 + s2;
s2 += "ef";
s3[2] = 'B';

See also: Constructors/destructors, Typecasts, Manipulation


PTypes home