| Version: 3.3.1

Public Member Functions | List of all members
wxStringBufferLength Class Reference
Class List by Category » Data Structures

`#include <wx/string.h>`

## Detailed Description

This helper class allows you to conveniently access the wxString internal buffer as a writable pointer and requires explicitly specifying the actual length.

For example, assuming you have a low-level OS function called `"int GetMeaningOfLifeAsString(char *)"` copying the value in the provided buffer (which must be writable, of course), and returning the actual length of the string, you might call it like this:

wxString theAnswer;
{
wxStringBufferLength theAnswerBuffer(theAnswer, 1024);
int nLength = GetMeaningOfLifeAsString(theAnswerBuffer);
theAnswerBuffer.SetLength(nLength);
} // The buffer is destroyed here, allowing the string to be used.
if ( theAnswer != "42" )
wxLogError("Something is very wrong!");
wxStringBufferLength
This helper class allows you to conveniently access the wxString internal buffer as a writable pointe...
Definition: string.h:2104
wxString
String class for passing textual data to or receiving it from wxWidgets.
Definition: string.h:372
wxLogError
void wxLogError(const char *formatString,...)
The functions to use for error messages, i.e.

Note that the string can't be used in any way while a buffer associated with it exists, the buffer must be destroyed to allow using the string again.

If possible, this class uses the internal wxString storage directly, however this may not be the case depending on wxWidgets build options.

Note that wxStringBuffer::SetLength must be called before wxStringBufferLength destructs.

##

Library: wxBase
Category: Data Structures

## Public Member Functions
| wxStringBufferLength (wxString &str, size_t len)
| Constructs a writable string buffer object associated with the given string and containing enough space for at least len characters. More...
| ~wxStringBufferLength ()
| Restores the string passed to the constructor to the usable state. More...
void | SetLength (size_t nLength)
| Sets the internal length of the string referred to by wxStringBufferLength to nLength characters. More...
wxChar * | operator wxChar * ()
| Returns the writable pointer to a buffer of the size at least equal to the length specified in the constructor. More...

## Constructor & Destructor Documentation

## ◆ wxStringBufferLength()

wxStringBufferLength::wxStringBufferLength | ( | wxString & | str,
|  | size_t | len
| ) |  |

Constructs a writable string buffer object associated with the given string and containing enough space for at least len characters.

## ◆ ~wxStringBufferLength()

wxStringBufferLength::~wxStringBufferLength | ( |  | ) |

Restores the string passed to the constructor to the usable state.

## Member Function Documentation

## ◆ operator wxChar *()

wxChar* wxStringBufferLength::operator wxChar * | ( |  | ) |

Returns the writable pointer to a buffer of the size at least equal to the length specified in the constructor.

## ◆ SetLength()

void wxStringBufferLength::SetLength | ( | size_t | nLength | ) |

Sets the internal length of the string referred to by wxStringBufferLength to nLength characters.

Must be called before wxStringBufferLength destructs.