Run Code  | API  | Code Wall  | Misc  | Feedback  | Login  | Theme  | Privacy  | Patreon 

MSVC_example_GetAllocLength

//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64

#include <iostream>

#include <atlsimpstr.h>
#include <atlstr.h>

int main()
{
    std::cout << "Hello, world!\n";
    
    CString str("dummy"); /* 5 chars + '\0' => bufsize=6 */

    _tprintf_s(_T("String length: %d\n"), str.GetLength()); /* reports 5 */
    _tprintf_s(_T("Allocated length: %d\n"), str.GetAllocLength()); /* reports 7 */
    str.Preallocate(100);
    _tprintf_s(_T("Allocated length: %d\n"), str.GetAllocLength()); /* reports 103 */
}
 run  | edit  | history  | help 0