本文整理汇总了C++中string::Data方法的典型用法代码示例。如果您正苦于以下问题:C++ string::Data方法的具体用法?C++ string::Data怎么用?C++ string::Data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类string
的用法示例。
在下文中一共展示了string::Data方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Truncate
bool BinaryFile::Truncate(const string& filename)
{
DWORD error = GetLastError();
HANDLE hFile = CreateFile(filename.Data(), GENERIC_WRITE, 0, 0, TRUNCATE_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
error = GetLastError();
if (error == ERROR_FILE_NOT_FOUND || error == ERROR_SUCCESS)
return true;
SetLastError(error);
CHECK_SYS_ERROR(L"Error can't truncate binary file " + filename);
CloseHandle(hFile);
CHECK_SYS_ERROR(L"Failed to truncate a file " + filename);
return true;
}
示例2: Save
bool BinaryFile::Save(const string& filename, const Buffer& buffer)
{
DWORD error = GetLastError();
HANDLE hFile = CreateFile(filename.Data(), GENERIC_WRITE, 0, 0,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
CHECK_SYS_ERROR(L"Error in binary file, open file for saving " + filename);
DWORD read;
WriteFile(hFile, (LPCVOID)buffer.StartPointer(), (DWORD)buffer.GetPosition(), &read, 0);
CHECK_SYS_ERROR(L"Error in binary file, can't write data to file " + filename);
if (read != buffer.GetPosition())
throw OSException(L"Error in binary file, written data is less than should be " + filename);
CloseHandle(hFile);
CHECK_SYS_ERROR(L"Saving binary file failed " + filename);
return true;
}
示例3: Load
bool BinaryFile::Load(const string& filename, Buffer& buffer)
{
DWORD error = GetLastError();
HANDLE hFile = CreateFile(filename.Data(), GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
CHECK_SYS_ERROR(L"Error in binary file, can't load it " + filename);
int size = GetFileSize(hFile, 0);
buffer.SetSize(size);
DWORD read;
ReadFile(hFile, buffer.StartPointer(), size, &read, 0);
CHECK_SYS_ERROR(L"Error in binary file, can't read data " + filename);
if (read != size)
throw OSException(L"Error in binary file, read data less than file contains, possible bad staff happenes " + filename);
CloseHandle(hFile);
CHECK_SYS_ERROR(L"Binary file load failed " + filename);
return true;
}
示例4: Append
bool BinaryFile::Append(const string& filename, const Buffer& buffer)
{
DWORD error = GetLastError();
HANDLE hFile = CreateFile(filename.Data(), GENERIC_WRITE, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
CHECK_SYS_ERROR(L"Error in binary file, can't open file for appending it " + filename);
DWORD offset = GetFileSize(hFile, 0);
SetFilePointer(hFile, offset, 0, FILE_BEGIN);
DWORD read;
WriteFile(hFile, (LPCVOID)buffer.StartPointer(), (DWORD)buffer.GetPosition(), &read, 0);
CHECK_SYS_ERROR(L"Error in binary file, can't write data to file " + filename);
if (read != buffer.GetPosition())
throw OSException(L"Error in binary file, written data is less than should be in " + filename);
CloseHandle(hFile);
CHECK_SYS_ERROR(L"Failed to append a file " + filename);
return true;
}
示例5: SetTitle
void Window::SetTitle(const string& text)
{
SetWindowText(m_windowHandle, text.Data());
}