本文整理汇总了C++中FileInputStream::close方法的典型用法代码示例。如果您正苦于以下问题:C++ FileInputStream::close方法的具体用法?C++ FileInputStream::close怎么用?C++ FileInputStream::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileInputStream
的用法示例。
在下文中一共展示了FileInputStream::close方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: generateNames
std::vector<std::string>* generateNames(int number) {
// this will avoid overriding previously generated names and keep consistent the results
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<std::string> names = split(fullNames, "\r");
cout << names.size() << endl;
std::vector<std::string> lastNames = split(fullLast, "\r");
cout << lastNames.size() << endl;
std::vector<std::string>* generated = new std::vector<std::string>();
for (int x = 0; x < number; 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;
generated->push_back(fullName);
}
fisNames->close();
fisLastNames->close();
delete fisNames;
delete fisLastNames;
return generated;
}
示例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;
}
}
示例3: LoadImage
void CImageLabel::LoadImage(const char * pImageName)
{
if ( m_pTGA )
delete m_pTGA;
// Load the Image
m_pTGA = LoadTGAForRes(pImageName);
if ( m_pTGA == NULL )
{
// we didn't find a matching image file for this resolution
// try to load file resolution independent
char sz[256];
sprintf(sz, "%s/%s",gEngfuncs.pfnGetGameDirectory(), pImageName );
FileInputStream* fis = new FileInputStream( sz, false );
m_pTGA = new BitmapTGA(fis,true);
fis->close();
}
if ( m_pTGA == NULL )
return; // unable to load image
int w,t;
m_pTGA->getSize( w, t );
setSize( XRES (w),YRES (t) );
setImage( m_pTGA );
}
示例4: FileOutputStream
TEST(TestCommand, testShownamespacesCommand) {
cout << "testShownamespacesCommand" << endl;
FileOutputStream* fos = new FileOutputStream("test.dat", "wb");
CommandWriter* writer = new CommandWriter(fos);
ShownamespacesCommand cmd;
cmd.setDB("testdb");
writer->writeCommand(&cmd);
fos->close();
delete fos;
delete writer;
FileInputStream* fis = new FileInputStream("test.dat", "rb");
CommandReader* reader = new CommandReader(fis);
Command* resCmd = reader->readCommand();
EXPECT_TRUE(resCmd->commandType() == SHOWNAMESPACES);
ShownamespacesCommand* sw = (ShownamespacesCommand*)resCmd;
EXPECT_TRUE(sw->DB()->compare("testdb") == 0);
fis->close();
delete resCmd;
delete fis;
delete reader;
}
示例5: fin
// protected
void
FileInputStreamTestCase::read (void)
{
FileInputStream fin (TEST_FILE_NAME);
int byte = fin.read ();
CPPUNIT_ASSERT ( (char)byte == 'T');
byte = fin.read ();
CPPUNIT_ASSERT ((char)byte == 'e');
unsigned char readBuf[11];
CPPUNIT_ASSERT (fin.read(readBuf, 10) == 10);
readBuf[10] = 0;
CPPUNIT_ASSERT (strncmp ((char*) readBuf, "st line 1\r", 10) == 0);
CPPUNIT_ASSERT (fin.read(readBuf, 4) == 4);
CPPUNIT_ASSERT (strncmp ((char*) readBuf, "\nTes", 4) == 0);
CPPUNIT_ASSERT_THROW (fin.read (0, 0), Exception);
CPPUNIT_ASSERT ((char)fin.read () == 't');
CPPUNIT_ASSERT (fin.read(readBuf, 0) == 0);
CPPUNIT_ASSERT (fin.read(readBuf, 10) == 10);
CPPUNIT_ASSERT (fin.read(readBuf, 4) == 4);
CPPUNIT_ASSERT (fin.read(readBuf, 10) == 6);
CPPUNIT_ASSERT (fin.read(readBuf, 4) == -1);
CPPUNIT_ASSERT (fin.read() == -1);
fin.close ();
}
示例6: ReadAllText
HRESULT CFileHelper::ReadAllText(LPCTSTR path, String & text)
{
FileInputStream ifs;
ifs.imbue(locale("chs"));
ifs.open(path,ifs.in);
if(!ifs.is_open()) return E_FAIL;
ifs.seekg(0,ifs.end);
int size=ifs.tellg();
ifs.seekg(0);
TCHAR * s=(TCHAR *)malloc(sizeof(TCHAR) * (size+1));
memset(s,0,sizeof(TCHAR)*(size+1));
ifs._Read_s(s,size ,sizeof(TCHAR) * size);
ifs.close();
text = s;
free(s);
return S_OK;
}
示例7: FileInputStream
//-----------------------------------------------------------------------------
// Purpose: Loads a .tga file and returns a pointer to the VGUI tga object
//-----------------------------------------------------------------------------
BitmapTGA *LoadTGA( const char* pImageName )
{
BitmapTGA *pTGA;
char sz[256];
sprintf(sz, "%%d_%s", pImageName);
// Load the Image
FileInputStream* fis = new FileInputStream( GetVGUITGAName(sz), false );
pTGA = new BitmapTGA(fis,true);
fis->close();
return pTGA;
}