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


C++ FileSystem::close方法代码示例

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


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

示例1: main

int main()
{
	FileSystem fileSystem;
	int errCode;
	
	//Format filesystem
	errCode = fileSystem.formatDisk();
	if(errCode == 1)
		cout<<"Filesystem formatting failed"<<endl;

	//Create a file and open it
	int file1 = fileSystem.create();
	int fileid1 = fileSystem.open(file1);

	//This is the data we'll write
	byte buffer[] = "Implementing File Systems, a test program";

	//Seek to a large distance so that we actually cause an indirection. As usual, we skip the first 10 blocks, and then write
	//Note that 256 is the block size. So, we seek to skip the first 10 direct blocks and then 10 bytes
	fileSystem.seek(fileid1, 10*256 + 10, SEEK_CUR);

	//Write 20 bytes at that position
	//If you could not write 20 bytes, that is definitely an error
	if(fileSystem.write(fileid1, buffer, 20) != 20)
		cerr<<"Error!"<<endl;

	//Close the file
	fileSystem.close(fileid1);
	
	//Reopen
	fileid1 = fileSystem.open(file1);

	/* Read from file currently does not work. So, commenting out */
	/*
	byte readbuf[16] = "\0";
	fileSystem.read(fileid1, readbuf, 6);

	cout<<"Read"<<readbuf<<"done" <<endl;
	*/

	//Owing to the non-functionality of read(), del() cannot be tested
	//fileSystem.del(fileid1);

	//By our write, we can calculate that the data block is 22
	//free() would free that block and add it to the free list
	//free() is a private function, however to show that it works, all you have to do is modify the FileSystem.h file and uncomment the following statement
	//fileSystem.free(22);
	
	//Also note that inumber() works. It is trivial to verify this
	//Only read() and del() do not work.

	return 0;
}
开发者ID:NOLFXceptMe,项目名称:FileSystemNS,代码行数:53,代码来源:main.cpp


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