本文整理汇总了C++中FileStream::Init方法的典型用法代码示例。如果您正苦于以下问题:C++ FileStream::Init方法的具体用法?C++ FileStream::Init怎么用?C++ FileStream::Init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileStream
的用法示例。
在下文中一共展示了FileStream::Init方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rename
Stream *HostOpenSaveGameStream(int nGame, bool fDelete)
{
char szT[PATH_MAX];
if (!FindSaveGame(nGame, szT, sizeof(szT)))
return NULL;
// rename to a temporary file before opening
char szTFull[PATH_MAX];
PrependSavesDirectory(szT, szTFull);
char szTempNameFull[PATH_MAX];
PrependSavesDirectory(kszTempName, szTempNameFull);
rename(szTFull, szTempNameFull);
// Get stream over temp file
FileStream *pstm = new FileStream();
if (pstm == NULL)
return NULL;
// If load is successful, and fDelete is True szTempName will be deleted
// if fDelete is false szTempName will be renamed to szSaveGame
if (!pstm->Init("rb", szTempNameFull, fDelete ? szTempNameFull : NULL, fDelete ? NULL : szTFull)) {
delete pstm;
return NULL;
}
return (Stream *)pstm;
}
示例2: strchr
Stream *HostNewSaveGameStream(int nGame, char *pszName)
{
// Get the old file name - we'll delete this if successful
char szOld[PATH_MAX];
char szOldFull[PATH_MAX];
if (!FindSaveGame(nGame, szOld, sizeof(szOld))) {
szOldFull[0] = 0;
} else {
PrependSavesDirectory(szOld, szOldFull);
}
// New file name
char szNew[PATH_MAX];
sprintf(szNew, "htsave%d_%s.bin", nGame, pszName);
// windows disallows ':' in a filename, so sub those out
char *pchInvalid = szNew;
do {
pchInvalid = strchr(pchInvalid, ':');
if (pchInvalid != 0)
*pchInvalid = '#';
} while (pchInvalid != 0);
char szNewFull[PATH_MAX];
PrependSavesDirectory(szNew, szNewFull);
// Get stream over temp file
FileStream *pstm = new FileStream();
if (pstm == NULL)
return NULL;
// If save is successful, szOld will be deleted and httempsave.bin
// will be renamed to szNew
char szTempSaveFull[PATH_MAX];
PrependSavesDirectory("httempsave.bin", szTempSaveFull);
if (!pstm->Init("wb", szTempSaveFull, szOldFull, szNewFull)) {
delete pstm;
return NULL;
}
return (Stream *)pstm;
}