本文整理汇总了C++中std::fstream::fail方法的典型用法代码示例。如果您正苦于以下问题:C++ fstream::fail方法的具体用法?C++ fstream::fail怎么用?C++ fstream::fail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::fstream
的用法示例。
在下文中一共展示了fstream::fail方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetUp
void SetUp() {
graph_file.open(GRAPH_FILENAME, std::fstream::in);
ASSERT_FALSE(graph_file.fail()) << "unable to open " << GRAPH_FILENAME;
solved_file.open(SOLUTION_FILENAME, std::fstream::in);
ASSERT_FALSE(solved_file.fail()) << "unable to open " << SOLUTION_FILENAME;
original = fs::DIMACSOriginalImporter<fs::FlowNetwork>(graph_file).read();
ASSERT_NE(original, nullptr) << "DIMACS parse error";
augmented = new fs::FlowNetwork(*original);
fs::DIMACSFlowImporter<fs::FlowNetwork>(solved_file, *augmented).read();
}
示例2: recvfile
long long TCPTransport::recvfile(std::fstream& ofs, long long offset, long long size)
{
if (!m_bConnected)
return -1;
if (ofs.bad() || ofs.fail())
return -1;
ofs.seekp(offset);
int block = 1000000;
char* buf = new char[block];
long long recd = 0;
while (recd < size)
{
int unit = int((size - recd) > block ? block : size - recd);
recv(buf, unit);
ofs.write(buf, unit);
recd += unit;
}
delete [] buf;
return recd;
}
示例3: sendfile
long long TCPTransport::sendfile(std::fstream& ifs, long long offset, long long size)
{
if (!m_bConnected)
return -1;
if (ifs.bad() || ifs.fail())
return -1;
ifs.seekg(offset);
int block = 1000000;
char* buf = new char[block];
long long sent = 0;
while (sent < size)
{
int unit = int((size - sent) > block ? block : size - sent);
ifs.read(buf, unit);
send(buf, unit);
sent += unit;
}
delete [] buf;
return sent;
}
示例4: read
virtual uint32 read(void *dataPtr, uint32 dataSize) {
_fileStream->read((char *)dataPtr, dataSize);
if (_fileStream->fail()) {
return 0;
}
return dataSize;
}
示例5: switch
bool
StandardFileProvider::open( std::string name, Mode mode )
{
ios::openmode om = ios::binary;
switch( mode ) {
case MODE_UNDEFINED:
case MODE_READ:
default:
om |= ios::in;
_seekg = true;
_seekp = false;
break;
case MODE_MODIFY:
om |= ios::in | ios::out;
_seekg = true;
_seekp = true;
break;
case MODE_CREATE:
om |= ios::in | ios::out | ios::trunc;
_seekg = true;
_seekp = true;
break;
}
_fstream.open( name.c_str(), om );
_name = name;
return _fstream.fail();
}
示例6:
bool
StandardFileProvider::seek( Size pos )
{
if( _seekg )
_fstream.seekg( pos, ios::beg );
if( _seekp )
_fstream.seekp( pos, ios::beg );
return _fstream.fail();
}
示例7: closeLogFile
void closeLogFile(std::fstream& logFile)
{
logFile.close();
if (logFile.fail())
{
std::cout << "ERROR while closing the log file" << std::endl;
exit(EXIT_FAILURE);
}
}
示例8:
MyFileReadStream(const char *filename) {
_stream = new std::fstream(filename, std::fstream::in);
if (_stream->fail()) {
isOpen = false;
delete _stream; // Primarily done to make sure we crash if this isn't handled.
_stream = NULL;
} else {
isOpen = true;
}
}
示例9: Saveunknown_input
/*
void TechBot::Saveunknown_input()
{
std::fstream fout("unknown.txt", std::ios::out);
if(fout.fail())
{
throw std::string("Unable to save Unknown Input List");
}
Vstr::const_iterator iter = ListOfUnknownInput.begin();
for( ; iter != ListOfUnknownInput.end(); ++iter )
{
fout << *iter << std::endl;
}
fout.flush();
fout.close();
}
*/
void TechBot::Savelog()
{
time_t ltime;
time(<ime);
logfile.open("log.txt", std::ios::out | std::ios::app);
if(logfile.fail())
{
throw std::string("can't save conversation log");
}
logfile << "\n\nConversation log - " << ctime(<ime) << std::endl;
}
示例10:
SeekableFileStream(const char *name) {
_fileStream = new std::fstream();
_fileStream->open(name, std::fstream::in | std::fstream::binary);
if (_fileStream->fail()) {
_length = -1;
} else {
_fileStream->seekg(0, std::ios_base::end);
_length = _fileStream->tellg();
_fileStream->seekg(0, std::ios_base::beg);
}
}
示例11: openLogFile
void openLogFile(std::fstream& logFile, const char* logFileName)
{
// Open the log file with append flag
logFile.open(logFileName, std::ios_base::app);
if (logFile.fail())
{
GET_TIME
std::cout << timeBuffer << "\t"
<< SYS_CALL_ERR_MSG("open", strerror(errno));
exit(EXIT_FAILURE);
}
}
示例12: seek
/**
* Sets the stream position indicator for the stream. The new position,
* measured in bytes, is obtained by adding offset bytes to the position
* specified by whence. If whence is set to SEEK_SET, SEEK_CUR, or
* SEEK_END, the offset is relative to the start of the file, the current
* position indicator, or end-of-file, respectively. A successful call
* to the seek() method clears the end-of-file indicator for the stream.
*
* @note The semantics of any implementation of this method are
* supposed to match those of ISO C fseek().
*
* @param offset the relative offset in bytes
* @param whence the seek reference: SEEK_SET, SEEK_CUR, or SEEK_END
* @return true on success, false in case of a failure
*/
virtual bool seek(int32 offset, int whence = SEEK_SET) {
if (whence == SEEK_SET) {
_stream->seekg(offset, std::ios::beg);
} else if (whence == SEEK_CUR) {
_stream->seekg(offset, std::ios::cur);
} else {
_stream->seekg(offset, std::ios::end);
}
if (_stream->fail())
return false;
if (_stream->bad())
return false;
return true;
}
示例13: OpenScriptStream
bool Dollar::OpenScriptStream(const char * pszName, std::fstream& stm)
{
for(int i = 0;;i++)
{
std::string fileName;
if(i == 0)
{
// use current dir
fileName = pszName;
}
else if (i == 1)
{
fileName = GetCurrentHost()->GetAppDataDir();
fileName += "\\";
fileName += pszName;
}
else if (i == 2)
{
// exe directory
char szPath[_MAX_PATH];
char szDrive[_MAX_PATH];
char szDir[_MAX_PATH];
GetModuleFileNameA(NULL, szPath, _countof(szPath));
_splitpath(szPath, szDrive, szDir, NULL, NULL);
fileName = szDrive;
fileName += szDir;
fileName += pszName;
}
else
{
break;
}
stm.open(fileName, std::fstream::in);
if(!stm.fail())
{
return true;
}
}
return false;
}
示例14: Read
bool xmlAttrib::Read(std::fstream &stream)
{
char t;
stream >> t;
if (stream.fail()) return false;
while (isspace(t))
{
stream >> t;
if (stream.fail()) return false;
}
if (isalpha(t)|| t=='_')
{
char buf[512];
char *p = buf;
buf[0] = 0;
while (isalnum(t)|| t=='_')
{
*p++ = t;
stream >> t;
if (stream.fail()) return false;
}
*p = 0;
name = buf;
while (isspace(t))
{
stream >> t;
if (stream.fail()) return false;
}
if (t != '=')
return false;
stream >> t;
if (stream.fail()) return false;
while (isspace(t))
{
stream >> t;
if (stream.fail()) return false;
}
if (t != '\"')
return false;
if (!ReadTextString(stream, value))
return false;
}