| Version: 3.2.5

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

`#include <wx/string.h>`

## Detailed Description

This tiny class allows you to conveniently access the wxString internal buffer as a writable pointer without any risk of forgetting to restore the string to the usable state later.

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

wxString theAnswer;
GetMeaningOfLifeAsString(wxStringBuffer(theAnswer, 1024));
if ( theAnswer != "42" )
wxLogError("Something is very wrong!");
wxStringBuffer::wxStringBuffer
wxStringBuffer(wxString &str, size_t len)
Constructs a writable string buffer object associated with the given string and containing enough spa...
wxString
String class for passing textual data to or receiving it from wxWidgets.
Definition: string.h:315
wxLogError
void wxLogError(const char *formatString,...)
The functions to use for error messages, i.e.

Note that the exact usage of this depends on whether or not `wxUSE_STL` is enabled. If `wxUSE_STL` is enabled, wxStringBuffer creates a separate empty character buffer, and if `wxUSE_STL` is disabled, it uses GetWriteBuf() from wxString, keeping the same buffer wxString uses intact. In other words, relying on wxStringBuffer containing the old wxString data is not a good idea if you want to build your program both with and without `wxUSE_STL`.

##

Library: wxBase
Category: Data Structures

## Public Member Functions

| wxStringBuffer (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...
| ~wxStringBuffer ()
| Restores the string passed to the constructor to the usable state by calling wxString::UngetWriteBuf() on it. More...
wxStringCharType * | operator wxStringCharType * ()
| Returns the writable pointer to a buffer of the size at least equal to the length specified in the constructor. More...

## Constructor & Destructor Documentation

## ◆ wxStringBuffer()

wxStringBuffer::wxStringBuffer | ( | 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.

Basically, this is equivalent to calling wxString::GetWriteBuf() and saving the result.

## ◆ ~wxStringBuffer()

wxStringBuffer::~wxStringBuffer | ( |  | ) |

Restores the string passed to the constructor to the usable state by calling wxString::UngetWriteBuf() on it.

## Member Function Documentation

## ◆ operator wxStringCharType *()

wxStringCharType* wxStringBuffer::operator wxStringCharType * | ( |  | ) |

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