C++ Builder 參考手冊 ? System::Sysutils ? StrBufSize
返回用 StrAlloc 或 AnsiStrAlloc 分配的字符串內(nèi)存里面最多可以存放多少個字符
頭文件:#include <System.SysUtils.hpp>
命名空間:System::Sysutils
函數(shù)原型:
unsigned __fastcall StrBufSize(const char *Str);
unsigned __fastcall StrBufSize(const System::WideChar *Str);
參數(shù):
- Str: 函數(shù) StrAlloc 或 AnsiStrAlloc 返回的字符串內(nèi)存
返回值:
- 返回值等于分配內(nèi)存時調(diào)用函數(shù) StrAlloc 或 AnsiStrAlloc 的參數(shù)值,即分配的內(nèi)存里面最多可以存放的字符個數(shù);
- 這是過時的函數(shù),因為 AnsiString 和 UnicodeString 都可以自動管理內(nèi)存,不需要這個函數(shù)了;
- 其中 const char *參數(shù)版本的函數(shù)是過時的函數(shù),由于 ANSI 編碼原因已經(jīng)移動到 System.AnsiStrings.hpp 這個頭文件里面了。
例子:字符串長度、字符串分配內(nèi)存的字符個數(shù)
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)); // 字符串分配內(nèi)存的字符個數(shù) = 100
Sysutils::StrDispose(pStr);
}
運行結(jié)果:

運行結(jié)果
相關(guān):
- 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
- <cstdlib>
C++ Builder 參考手冊 ? System::Sysutils ? StrBufSize