Other constructors |
![]() |
|
|
|
|
These constructors will initialize the string object to hold a copy of the passed C string. If prealloc is specified, a buffer for that number of characters will be allocated; otherwise the buffer size will be chosen automatically depending on the length of source .
Example 1: print a string to the console
Str test ("This is a test\n");
printf(test);
Example 2: print two strings to the console, seamlessly convert between ANSI and Unicode
// Example will not compile under Linux
Str test1 ("ANSI string");
Str test2 (L"Unicode string");
printf("[%s] [%s]\n", test1, test2);
// To compile in a Unicode project, replace the previous statement with
// wprintf(L"[%s] [%s]\n", test1, test2);
|
Note for projects using Unicode Because a constructor is defined for both ANSI and Unicode strings, you will be able to use both forms in your application, whether you have defined _UNICODE or not. However, using the native form (ANSI strings in regular applications, Unicode strings in _UNICODE applications) is much faster; the built-in conversion requires additional processing.
|
|
|
|
Initialize the string to contain a single character. This character cannot be null.
If prealloc is specified, a buffer for that number of characters will be allocated; otherwise a small buffer size will be chosen automatically.
|
|
|
Initialize the new instance to contain a copy of the passed CString value. If the prealloc parameter does not equal zero, the string buffer will be set to the specified size; otherwise the size will be chosen automatically.
See also: Constructors & utility