当前位置: 首页>>代码示例>>C++>>正文


C++ fstream::setstate方法代码示例

本文整理汇总了C++中std::fstream::setstate方法的典型用法代码示例。如果您正苦于以下问题:C++ fstream::setstate方法的具体用法?C++ fstream::setstate怎么用?C++ fstream::setstate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::fstream的用法示例。


在下文中一共展示了fstream::setstate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: OpenUtf8FStreamForRead

void OpenUtf8FStreamForRead(std::fstream &aFStream, const char *aUtf8FileName)
{
	// Unfortunately the windows C++ STL library will not open files specified via a UTF-8 filename.
	// The workaround is to convert the UTF-8 name to the short DOS compatible name and open that instead

	// First convert the UTF-8 name to UTF-16 for use with the windows APIs
	WCHAR *utf16Name = WindowsUtf8ToUtf16(aUtf8FileName);

	// Obtain short DOS compatible name for file
	WCHAR *utf16NameDos = WindowsRetrieveDosName(utf16Name);
	if(utf16NameDos == 0)
		{
		aFStream.setstate(std::ios_base::badbit);
		delete [] utf16Name;
		return;
		}

	char *utf8NameDos = WindowsUtf16ToUtf8(utf16NameDos);

	aFStream.open(utf8NameDos, std::ios_base::binary | std::ios_base::in);

	delete [] utf8NameDos;
	delete [] utf16NameDos;
	delete [] utf16Name;
	return;
}
开发者ID:cdaffara,项目名称:symbiandump-os2,代码行数:26,代码来源:utils.cpp

示例2: OpenUtf8FStreamForWrite

void OpenUtf8FStreamForWrite(std::fstream &aFStream, const char *aUtf8FileName)
{
	// Unfortunately the windows C++ STL library will not open files specified via a UTF-8 filename.
	// The workaround is to make sure the file already exists and then convert the UTF-8 name to the short DOS compatible name 
	// and open that instead

	// First convert the UTF-8 name to UTF-16 for use with the windows APIs
	WCHAR *utf16Name = WindowsUtf8ToUtf16(aUtf8FileName);

	// Make sure the file exists
	HANDLE fh = CreateFileW((WCHAR *)utf16Name, GENERIC_WRITE, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, 0,  CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 );
	if(fh == INVALID_HANDLE_VALUE)
		{
		dbg << Log::Indent() << "Failed to create file '" << aUtf8FileName << "'" << Log::Endl();
		aFStream.setstate(std::ios_base::badbit);
		delete [] utf16Name;
		return;
		}
	// Close handle
	CloseHandle(fh);


	// Obtain short DOS compatible name for file
	WCHAR *utf16NameDos = WindowsRetrieveDosName(utf16Name);
	if(utf16NameDos == 0)
		{
		aFStream.setstate(std::ios_base::badbit);
		delete [] utf16Name;
		return;
		}

	char *utf8NameDos = WindowsUtf16ToUtf8(utf16NameDos);

	aFStream.open(utf8NameDos, std::ios_base::binary | std::ios_base::trunc | std::ios_base::out);

	delete [] utf8NameDos;
	delete [] utf16NameDos;
	delete [] utf16Name;
	return;
}
开发者ID:cdaffara,项目名称:symbiandump-os2,代码行数:40,代码来源:utils.cpp


注:本文中的std::fstream::setstate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。