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


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

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


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

示例1: FileOutputStream

TEST(TestCommand, testInsertCommand) {
	cout << "testInsertCommand" << endl;
	FileOutputStream* fos = new FileOutputStream("test.dat", "wb");

	CommandWriter* commandWriter = new CommandWriter(fos);
	InsertCommand cmd;
	cmd.setDB("testdb");
	cmd.setNameSpace("test.namespace.db");
	BSONObj* obj = new BSONObj();
	obj->add("name", "Cross");
	obj->add("age", 18);
	cmd.setBSON(obj);

	commandWriter->writeCommand(&cmd);

	fos->close();
	delete fos;
	delete commandWriter;

	FileInputStream* fis = new FileInputStream("test.dat", "rb");
	CommandReader* reader = new CommandReader(fis);
	InsertCommand* rdCmd = (InsertCommand*) reader->readCommand();
	EXPECT_TRUE(rdCmd != NULL);
	EXPECT_TRUE(rdCmd->nameSpace()->compare("test.namespace.db") == 0);
	EXPECT_TRUE(rdCmd->DB()->compare("testdb") == 0);
	const BSONObj* objResult = rdCmd->bson();
	EXPECT_TRUE(objResult != NULL);
	EXPECT_TRUE(objResult->has("name"));	
	EXPECT_TRUE(objResult->getString("name").compare("Cross") == 0);
}
开发者ID:FikiHafana,项目名称:djondb,代码行数:30,代码来源:main.cpp

示例2: FileInputStream

TEST(testIndexP, generateNames) {
	// this will avoid overriding previously generated names and keep consistent the results
	if (!existFile("names.txt")) {
		FileInputStream* fisNames = new FileInputStream("names.csv", "r");
		const char* fullNames = fisNames->readFull();
		FileInputStream* fisLastNames = new FileInputStream("last.csv", "r");
		const char* fullLast = fisLastNames->readFull();

		std::vector<string> names = split(fullNames, "\r");
		cout << names.size() << endl;
		std::vector<string> lastNames = split(fullLast, "\r");
		cout << lastNames.size() << endl;

		FileOutputStream* fos = new FileOutputStream("names.txt", "w+");
		for (int x = 0; x < 10000000; x++) {
			int i = rand() % names.size();
			std::string name = names.at(i);

			i = rand() % lastNames.size();
			std::string lastName = lastNames.at(i);

			std::string fullName = name + " " + lastName;

			fos->writeString(fullName);
		}

		fos->close();
		fisNames->close();
		fisLastNames->close();

		delete fos;
		delete fisNames;
		delete fisLastNames;
	}
}
开发者ID:FikiHafana,项目名称:djondb,代码行数:35,代码来源:testIndexP.cpp

示例3: ff

// protected
void
FileOutputStreamTestCase::seek (void)
{
    File ff (TEST_FILE_NAME);
    if (ff.exists () == false)
        ff.create ();

    FileOutputStream fout (TEST_FILE_NAME, OPEN_MODE);
    String ss = "dflajdkjasldjfaksldjfsalkdjalksdjadflajdkjasldjfaksldjfsalkdjalksdjadflajdkjasldjfaksldjfsalkdjalksdjadflajdkjasldjfaksldjfsalkdjalksdjadflajdkjasldjfaksldjfsalkdjalksdja sd";
    fout.write ((unsigned char *)ss.getCStr (), ss.getLength ());
    fout.flush ();

    CPPUNIT_ASSERT_THROW (fout.seek (-1, BEGIN_ORIGIN), Exception);
    CPPUNIT_ASSERT (fout.seek (3, BEGIN_ORIGIN) == 3);
    CPPUNIT_ASSERT (fout.seek (21, BEGIN_ORIGIN) == 21);
    CPPUNIT_ASSERT (fout.seek (38, BEGIN_ORIGIN) == 38);

    CPPUNIT_ASSERT (fout.seek (-7, CURRENT_ORIGIN) == 31);
    CPPUNIT_ASSERT (fout.seek (2, CURRENT_ORIGIN) == 33);
    CPPUNIT_ASSERT_THROW (fout.seek (-73, CURRENT_ORIGIN), Exception);
    CPPUNIT_ASSERT (fout.seek (24, CURRENT_ORIGIN) == 57);
    CPPUNIT_ASSERT (fout.seek (24, CURRENT_ORIGIN) == 81);

    fout.close ();
}
开发者ID:hanxin1987216,项目名称:DTL,代码行数:26,代码来源:fileoutputtc.cpp

示例4: f

// protected
void
FileOutputStreamTestCase::write (void)
{
    File f (TEST_FILE_NAME);
    if (f.exists ())
        f.remove ();

    FileOutputStream out (TEST_FILE_NAME, CREATE_NEW_MODE);
    const char* str = "Test line 1\r\nTest line 2\r\nTest line 3";
    out.write ((const unsigned char*)str, strlen (str));
    out.close ();


    File ff (TEST_FILE_NAME);
    CPPUNIT_ASSERT (ff.getLength () == strlen (str));


    File filer (TEST_FILE_NAME1);
    if (filer.exists ())
        filer.remove ();

    FileOutputStream fout5(TEST_FILE_NAME1, APPEND_MODE);
    String s2 = "test line";
    fout5.write ((unsigned char*)s2.getCStr (), s2.getLength ());
    File filetest (TEST_FILE_NAME1);
    CPPUNIT_ASSERT (filetest.getLength () == s2.getLength ());
    fout5.close ();

}
开发者ID:hanxin1987216,项目名称:DTL,代码行数:30,代码来源:fileoutputtc.cpp

示例5: WriteText

HRESULT CFileHelper::WriteText(LPCTSTR path, LPCTSTR text)
{
	BOOL exists = FALSE;

	HRESULT hr = Contains(path, exists);
	if(FAILED(hr)) return hr;

	if( !exists)
	{
		String folder ;
		if(SUCCEEDED( GetParentFolder(path, folder)))
		{
			hr = CreateFolder(folder.c_str());	
			if(FAILED(hr)) return hr;
		}
	}	

	FileOutputStream ofs;

	ofs.imbue(locale("chs"));

	ofs.open(path);

	if(!ofs.is_open()) return E_FAIL;

	ofs.clear();

	ofs.write(text, STRLEN(text)/* *sizeof(TCHAR)*/);

	ofs.close();

	return S_OK;
}
开发者ID:bestustc,项目名称:MyTutorial,代码行数:33,代码来源:FileHelper.cpp

示例6: file

// protected
void
FileOutputStreamTestCase::flush (void)
{
    File file (_T("testflush"));
    if (file.exists ())
        file.remove ();

    FileOutputStream fout (_T("testflush"), CREATE_NEW_MODE);

    fout.write ((unsigned char*)"1", 1);
    fout.flush ();
    CPPUNIT_ASSERT (file.getLength () == 1);


    fout.close ();
    file.remove ();
}
开发者ID:hanxin1987216,项目名称:DTL,代码行数:18,代码来源:fileoutputtc.cpp

示例7: fout

// protected
void
FileOutputStreamTestCase::ctors (void)
{

    File f1 (TEST_FILE_NAME);
    if (f1.exists () == false)
        f1.create ();

    // open mode
    FileOutputStream fout (TEST_FILE_NAME, OPEN_MODE);
    fout.close ();


    // open or create mode
    File file (TEST_FILE_NAME);
    FileOutputStream fout1 (file, OPEN_OR_CREATE_MODE);
    fout1.close ();


    // read_share
    FileOutputStream fout2(TEST_FILE_NAME, CREATE_MODE, READ_SHARE);
    fout2.close ();
}
开发者ID:hanxin1987216,项目名称:DTL,代码行数:24,代码来源:fileoutputtc.cpp

示例8: convert

void HeightMap::convert(const String& path) {
	FileInputStream* reader = NULL;
	try {
		reader = new FileInputStream(new File(path));
	} catch (...) {
		System::out << "could not open reader" << endl;

		exit(1);
	}

	FileOutputStream* writer = NULL;

	try {
		writer = new FileOutputStream(new File("converted_" + path));
	} catch (...) {
		System::out << "could not open writer" << endl;
		exit(1);
	}

	//FileOutputStream* writer = new FileOutputStream(new File("converted_" + path));

	byte emptybuffer[PLANEWIDTH * HEIGHTSIZE];

	for (int i = 0; i < PLANEWIDTH * HEIGHTSIZE; ++i)
		emptybuffer[i] = 0;

	// first 2 lines
	for (int i = 0; i < 2 * 64; ++i) {
		for (int j = 0; j < PLANEWIDTH; ++j)
			writer->write(emptybuffer, PLANEWIDTH * HEIGHTSIZE);
	}

	int planeIndexX = 2;
	int planeIndexY = 2;

	// inner 60 lines
	for (int i = 0; i < 60; ++i) {
		// 2 beginning plane
		for (int j = 0; j < 2 * PLANEWIDTH; ++j)
			writer->write(emptybuffer, PLANEWIDTH * HEIGHTSIZE);

		// inner 60 planes
		for (int j = 0; j < 60; ++j) {
			System::out << "\r writing(" << planeIndexX << ", " << planeIndexY << ")";

			float plane[PLANEWIDTH * PLANEWIDTH];
			readPlaneForConversion(reader, plane, planeIndexX - 2, planeIndexY - 2);

			writer->write((byte*) plane, PLANEWIDTH * PLANEWIDTH * HEIGHTSIZE);

			++planeIndexX;
		}

		planeIndexX = 2;
		++planeIndexY;

		// 2 ending plane
		for (int j = 0; j < 2 * PLANEWIDTH; ++j)
			writer->write(emptybuffer, PLANEWIDTH * HEIGHTSIZE);
	}

	//last 2 lines
	for (int i = 0; i < 2 * 64; ++i) {
		for (int j = 0; j < PLANEWIDTH; ++j)
			writer->write(emptybuffer, PLANEWIDTH * HEIGHTSIZE);
	}

	writer->close();

	delete writer;
	delete reader;
}
开发者ID:JigglyPoofSWG,项目名称:BSS,代码行数:72,代码来源:HeightMap.cpp


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