本文整理汇总了C++中std::ifstream::exceptions方法的典型用法代码示例。如果您正苦于以下问题:C++ ifstream::exceptions方法的具体用法?C++ ifstream::exceptions怎么用?C++ ifstream::exceptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::ifstream
的用法示例。
在下文中一共展示了ifstream::exceptions方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: open
/// open file for reading
void open(const std::string& a_fname) {
if (m_open) return;
// make sure exception thrown in case of error
m_file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
m_file.open(a_fname.c_str(), std::ios::in | std::ios::binary);
// further read can set failbit in case there is not enough data
// this case should not throw an exception in our class
m_file.exceptions(std::ifstream::badbit);
m_open = true;
m_fname = a_fname;
m_buf.reset();
BOOST_ASSERT(m_buf.capacity() > 0);
}
示例2: ReadPicData
bool ReadPicData (std::ifstream &fdata, unsigned char *buffer, int frame_size)
{
bool ret_stat = true;
ios::iostate oldExceptions = fdata.exceptions();
fdata.exceptions (ios::failbit | ios::badbit);
try
{
fdata.read ((char *)buffer, frame_size);
}
catch (...)
{
ret_stat = false;
}
fdata.exceptions (oldExceptions);
return ret_stat;
}
示例3: open
void open(std::ifstream& stream) const {
stream.open(m_path.c_str(), std::ios::in|std::ios::binary);
if (!stream.is_open()) {
LOG4CXX_ERROR(m_logger, "Couldn't open file [" << m_path << "]");
MR4C_THROW(std::logic_error, "Couldn't open file [" << m_path << "]");
}
stream.exceptions(std::ifstream::badbit);
}
示例4: open
/**
* Opens the prt_ifstream to read from the specified file
* @param file Path to the file to read particles from
*/
void open( const std::string& file ) {
m_fin.open( file.c_str(), std::ios::in | std::ios::binary );
if( m_fin.fail() )
throw std::ios_base::failure( "Failed to open file \"" + file + "\"" );
m_filePath = file;
m_fin.exceptions( std::ios::badbit );
read_header();
init_zlib();
}
示例5: runtime_error
PolyFileReader (Boundary *b_, const string &polyfilename)
: is (polyfilename.c_str ()),
b (b_)
{
if (!is) {
throw std::runtime_error ("Cannot open \"" +
polyfilename + "\"");
}
is.exceptions (std::ios::failbit | std::ios::badbit);
vertex_map.reserve (1000);
}
示例6: Skip
bool Skip (std::ifstream &fdata, int start_frame, int frame_size)
{
bool ret_stat = true;
ios::iostate oldExceptions = fdata.exceptions();
fdata.exceptions (ios::failbit | ios::badbit);
try
{
unsigned char* buffer = new unsigned char[frame_size];
for (int i=0; i<start_frame; ++i)
ReadPicData(fdata, buffer, frame_size);
delete[] buffer;
}
catch (...)
{
std::cerr << "Skipping of first "<< start_frame << " frames failed"
<< std::endl;
ret_stat = false;
}
fdata.exceptions (oldExceptions);
return ret_stat;
}
示例7: LoadFileToString
void SettingsFile::LoadFileToString(std::ifstream& file, SettingsFile::StringVector& lines, const std::string& file_name)
{
// First, tell the file not to throw any exceptions.
file.exceptions(std::ios_base::goodbit);
// Now load each line from the file into a string.
while(file.good() == true)
{
std::string line;
std::getline(file, line);
lines.push_back(line);
}
// If an error occurred while reading (other than reaching EOF), then throw a FileReadException.
if(file.fail() == true && file.eof() == false)
{
file.close();
throw FileReadException(file_name);
}
}
示例8: OBJParser
OBJParser(const char* filename, std::vector<glm::vec3>& positions,
std::vector<glm::vec2>& texcoords,
std::vector<glm::vec3>& normals,
std::vector<GLuint>& position_indices,
std::vector<GLuint>& texcoord_indices,
std::vector<GLuint>& normal_indices)
: filename(filename),
positions(positions),
texcoords(texcoords),
normals(normals),
position_indices(position_indices),
texcoord_indices(texcoord_indices),
normal_indices(normal_indices),
ifs(filename, std::ifstream::in),
lineno(1),
charno(0),
type(UNKNOWN) {
ifs.exceptions(std::ifstream::failbit | std::ifstream::badbit);
}
示例9: OpenInputStream
void WindowsFileOpener::OpenInputStream( std::ifstream &stream, std::ios_base::openmode openModeRequired )
{
stream.exceptions( std::ifstream::failbit | std::ifstream::badbit | std::ifstream::eofbit );
stream.open( _filePath.c_str(), openModeRequired );
}