Other constructors

Web Site  Methods

 
Str::Str (const STRACHAR* source)
Str::Str (CPOS prealloc, const STRACHAR* source)

 
Str::Str (const STRWCHAR* source)
Str::Str (CPOS prealloc, const STRWCHAR* source)
Available only on platforms with Unicode support

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.

 

 

 

Str::Str (STRCHAR source)
Str::Str (CPOS prealloc, STRCHAR source)

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.

 

Str::Str (const CString& source, CPOS prealloc = 0)
Available only for MFC-based Windows projects

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