StrBufSize - C++ Builder

C++ Builder 参考手册 ➙ System::Sysutils ➙ StrBufSize


返回用 StrAlloc 或 AnsiStrAlloc 分配的字符串内存里面最多可以存放多少个字符

头文件:#include
命名空间:System::Sysutils
函数原型:

unsigned __fastcall StrBufSize(const char *Str);
unsigned __fastcall StrBufSize(const System::WideChar *Str);

参数:

  • Str: 函数 StrAlloc 或 AnsiStrAlloc 返回的字符串内存

返回值:

  • 返回值等于分配内存时调用函数 StrAlloc 或 AnsiStrAlloc 的参数值,即分配的内存里面最多可以存放的字符个数;
  • 这是过时的函数,因为 AnsiString 和 UnicodeString 都可以自动管理内存,不需要这个函数了;
  • 其中 const char *参数版本的函数是过时的函数,由于 ANSI 编码原因已经移动到 System.AnsiStrings.hpp 这个头文件里面了。

例子:字符串长度、字符串分配内存的字符个数

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    wchar_t *pStr = Sysutils::StrAlloc(100);
    std::wcscpy(pStr, L"Hello, Hsuanlu!");
    Memo1->Lines->Add(pStr); // 输出字符串
    Memo1->Lines->Add(std::wcslen(pStr)); // 字符串长度 = 15
    Memo1->Lines->Add(Sysutils::StrBufSize(pStr)); // 字符串分配内存的字符个数 = 100
    Sysutils::StrDispose(pStr);
}

运行结果:

运行结果

相关:

  • System::Sysutils::StrAlloc
  • System::Sysutils::AnsiStrAlloc
  • System::Sysutils::WideStrAlloc
  • System::Sysutils::StrBufSize
  • System::Sysutils::StrNew
  • System::Sysutils::StrDispose
  • System::Sysutils
  • System::AnsiString
  • System::UnicodeString
  • System::StringOfChar
  • System
  • std::malloc
  • std::calloc
  • std::realloc
  • std::free

C++ Builder 参考手册 ➙ System::Sysutils ➙ StrBufSize

你可能感兴趣的:(StrBufSize - C++ Builder)