C++ Builder 參考手冊 ? System::Sysutils ? StrNew
使用 StrAlloc 分配內(nèi)存并且把字符串復(fù)制到這里
頭文件:#include <System.SysUtils.hpp>
命名空間:System::Sysutils
函數(shù)原型:
char *__fastcall StrNew(const char *Str);
System::WideChar *__fastcall StrNew(const System::WideChar *Str);
參數(shù):
- Str: 要復(fù)制的字符串
返回值:
- 使用 StrAlloc 或 AnsiStrAlloc 分配一個 Delphi 兼容的字符串內(nèi)存,然后把字符串 Str 復(fù)制到分配的內(nèi)存,函數(shù)返回指向新分配內(nèi)存里面字符串的指針;
- 如果參數(shù) Str 等于 nullptr,函數(shù)直接返回 nullptr;
- 如果要釋放這個函數(shù)分配的內(nèi)存,需要使用 StrDispose 函數(shù);
- 可以通過函數(shù) StrLen 獲取字符串長度;
- 可以通過函數(shù) StrBufSize 獲取內(nèi)存里面可以存放的字節(jié)數(shù),即分配內(nèi)存時調(diào)用 StrAlloc 或 AnsiStrAlloc 的參數(shù)值;
- 實際分配內(nèi)存的字節(jié)數(shù)等于 Str 字符串長度 + 結(jié)束符 + 4個字節(jié) 占用的內(nèi)存,有關(guān)分配內(nèi)存的詳細(xì)說明請參考 StrAlloc 和 AnsiStrAlloc。
例子:請參考 StrLen 和 StrBufSize 的例子。
相關(guān):
- System::Sysutils::StrAlloc
- System::Sysutils::AnsiStrAlloc
- System::Sysutils::WideStrAlloc
- System::Sysutils::StrBufSize
- System::Sysutils::StrLen
- System::Sysutils::StrNew
- System::Sysutils::StrDispose
- System::Sysutils
- System::UnicodeString
- System::StringOfChar
- System
- std::malloc
- std::calloc
- std::realloc
- std::free
- <cstdlib>
C++ Builder 參考手冊 ? System::Sysutils ? StrNew