本文整理汇总了C++中String::DrivePointer方法的典型用法代码示例。如果您正苦于以下问题:C++ String::DrivePointer方法的具体用法?C++ String::DrivePointer怎么用?C++ String::DrivePointer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String::DrivePointer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OpenReadOnlyTest
Bool OpenReadOnlyTest()
{
Bool result = true;
File* file;
String text;
UInt fileSize;
//File does not exists, open it and it will fail
File::Delete(_fileName);
file = File::OpenReadOnly(_fileName);
CHECK file == 0;
//File exists, open it and it will work, write to it and it will fail
CHECK (file = File::Create(_fileName));
file->Write((VoidPtr)_fileName, String::CStrByteSize(_fileName));
DeletePtr(file);
CHECK (file = File::OpenReadOnly(_fileName));
fileSize = ToUInt(file->GetFileSize());
text.Reserve(fileSize / sizeof(TChar));
file->Read(text.DrivePointer(fileSize / sizeof(TChar)), fileSize);
CHECK text == _fileName;
DeletePtr(file);
File::Delete(_fileName);
return result;
}
示例2: ReadAll
Bool TextFile::ReadAll(CStr fileName, String& text, Exception* out_ex)
{
ASSERT_PARAMETER(fileName);
Bool result = false;
File* file = File::Open(fileName, File::Disposition::OpenExisting, File::Access::AccessRead, File::Flags::ShareRead | File::Flags::OptimizeForSequentialAccess, out_ex);
if(file)
{
UInt fileSize = ToUInt(file->GetFileSize());
UInt length = fileSize / sizeof(TChar);
//If fileSize is odd then +1 will compensate the division rounding
if(fileSize % 2)
++fileSize;
text.Reserve(length);
TChar* buffer = text.DrivePointer(length);
result = file->Read(buffer, fileSize);
GALATEA_DELETE_PTR(file);
if(!result)
{
text.Clear();
text.Shrink();
}
}
return result;
}
示例3: ReadAll
String TextFile::ReadAll(CStr fileName)
{
Assert(fileName);
File* file;
String text;
UInt fileSize;
UInt length;
TChar* buffer;
file = File::OpenReadOnly(fileName);
if(file)
{
fileSize = ToUInt(file->GetFileSize());
length = fileSize / sizeof(TChar);
text.Reserve(length);
buffer = text.DrivePointer(length);
file->Read(buffer, fileSize);
DeletePtr(file);
}
return text;
}