本文整理汇总了C++中std::istream::fail方法的典型用法代码示例。如果您正苦于以下问题:C++ istream::fail方法的具体用法?C++ istream::fail怎么用?C++ istream::fail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::istream
的用法示例。
在下文中一共展示了istream::fail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: gene
int
GA3DBinaryStringGenome::read(std::istream & is)
{
static char c;
unsigned int i=0, j=0, k=0;
do{
is >> c;
if(isdigit(c)){
gene(i++, j, k, ((c == '0') ? 0 : 1));
if(i >= nx){
i=0;
j++;
}
if(j >= ny){
j=0;
k++;
}
}
} while(!is.fail() && !is.eof() && k < nz);
_evaluated = gaFalse;
if(is.eof() &&
((k < nz) || // didn't get some lines
(j < ny && j != 0) || // didn't get some lines
(i < nx && i != 0))){ // didn't get some lines
GAErr(GA_LOC, className(), "read", gaErrUnexpectedEOF);
is.clear(std::ios::badbit | is.rdstate());
return 1;
}
return 0;
}
示例2: storeStreamToTempFile
std::string ImageCoder::storeStreamToTempFile(std::istream & stream)
{
std::string fileName;
{
char fileNameBuffer[L_tmpnam];
char * result = tmpnam(fileNameBuffer);
if (result == nullptr)
return fileName; // empty file name indicates a problem ...
fileName.assign(result);
}
std::ofstream file(fileName, std::ofstream::binary);
if (file.fail())
std::runtime_error("failed to create temp file: '" + fileName + "'");
try
{
file << stream.rdbuf();
if (file.fail() || stream.fail())
std::runtime_error("failed to write to temp file: '" + fileName + "'");
}
catch (const std::iostream::failure &)
{
std::runtime_error("failed to write to temp file: '" + fileName + "', caught failure");
}
return fileName;
}
示例3: runtime_error
static uint8_t readHexByte(std::istream & s)
{
std::istream::sentry sentry(s, true);
if (sentry)
{
char c1 = 0, c2 = 0;
s.get(c1);
s.get(c2);
if (s.fail())
{
if (s.eof())
{
throw std::runtime_error("Unexpected end of line.");
}
else
{
throw std::runtime_error("Failed to read hex digit.");
}
}
int v1 = hexDigitValue(c1);
int v2 = hexDigitValue(c2);
if (v1 < 0 || v2 < 0)
{
throw std::runtime_error("Invalid hex digit.");
}
return v1 * 16 + v2;
}
return 0;
}
示例4: process
void process(const std::string& fname, std::istream& sin = std::cin,
std::ostream& sout = std::cout)
{
// Communication system
libcomm::commsys<S, C> *system = libcomm::loadfromfile<
libcomm::commsys<S, C> >(fname);
std::cerr << system->description() << std::endl;
// Initialize system
libbase::randgen r;
r.seed(0);
system->seedfrom(r);
// Repeat until end of stream
for (int i=0; !sin.eof(); i++)
{
// skip any comments
libbase::eatcomments(sin);
// attempt to read a block of the required size
C<int> source(system->input_block_size());
source.serialize(sin);
// stop here if something went wrong (e.g. incomplete block)
if (sin.fail())
{
std::cerr << "Failed to read block " << i << std::endl;
break;
}
// encode block and push to output stream
C<S> transmitted = system->encode_path(source);
transmitted.serialize(sout, '\n');
// skip any trailing whitespace (before check for EOF)
libbase::eatwhite(sin);
}
// Destroy what was created on the heap
delete system;
}
示例5: sRead
OSG_USING_NAMESPACE
bool sRead(std::istream &file,
void *value,
Int32 size,
bool swapit)
{
Char8 buffer[4];
if(size > 4)
return false;
if(swapit)
{
file.read(buffer, size);
for(Int32 i = 0; i < size; i++)
{
static_cast<Char8 *>(value)[i] = buffer[size - i - 1];
}
}
else
{
file.read (static_cast<Char8 *>(value), size);
}
bool failed = file.fail();
return !failed;
}
示例6: sizeof
template<class T> void WavFileInputSoundStream::read(std::istream & is, T & t)
{
is.read(reinterpret_cast<char *>(&t), sizeof(T));
if(is.eof()) throw std::string("EOF");
if(is.fail()) throw std::string("FAIL");
if(is.bad()) throw std::string("BAD");
}
示例7: ReadValueStr
std::string ReadValueStr(std::string prompt /*= std::string()*/, std::istream& in /*= std::cin*/, std::ostream* out /*= &std::cout*/)
{
if (out)
(*out) << prompt;
std::string input;
bool success = false;
while (!success)
{
std::getline(in, input);
if (in.fail())
{
if (in.eof())
{
in.clear();
throw EOFCharacterValue();
}
else
{
in.clear();
if (out)
(*out) << "Invalid value. Please try again." << std::endl;
else
throw InvalidValue("ReadValue: Invalid value found with no out stream.");
continue;
}
}
success = true;
}
return input;
}
示例8: update
void IndexStreamBuffer::update(std::istream& data)
{
std::size_t size = count * static_cast<std::size_t>(format);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, nullptr, GL_STREAM_DRAW);
void* map = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
if (map == nullptr) {
glGetError();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
throw Error("Failed to map index buffer.", __FILE__, __LINE__);
}
data.read(reinterpret_cast<char*>(map), size);
if (data.fail() || data.gcount() != static_cast<std::streamsize>(size)) {
glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
throw IOException("Failed to read index buffer from stream.");
}
if (!glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER)) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
throw Error("Failed to unmap index buffer.", __FILE__, __LINE__);
}
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
if (glGetError() != GL_NO_ERROR) {
throw Error("Failed to update index buffer.", __FILE__, __LINE__);
}
}
示例9: CreateInterfaceValidated
OpenRAVE::InterfaceBasePtr CreateInterfaceValidated(OpenRAVE::InterfaceType type,
std::string const &interface_name, std::istream &sinput, OpenRAVE::EnvironmentBasePtr env)
{
if (type == OpenRAVE::PT_Sensor && interface_name == "bhtactilesensor") {
std::string node_name, owd_namespace, robot_name, link_prefix;
sinput >> node_name >> owd_namespace >> robot_name >> link_prefix;
// Initialize the ROS node.
RAVELOG_DEBUG("name = %s namespace = %s\n", node_name.c_str(), owd_namespace.c_str());
if (sinput.fail()) {
RAVELOG_ERROR("BHTactileSensor is missing the node_name, owd_namespace, robot_name, or link_prefix parameter(s).\n");
return OpenRAVE::InterfaceBasePtr();
}
if (!ros::isInitialized()) {
int argc = 0;
ros::init(argc, NULL, node_name, ros::init_options::AnonymousName);
RAVELOG_DEBUG("Starting ROS node '%s'.\n", node_name.c_str());
} else {
RAVELOG_DEBUG("Using existing ROS node '%s'\n", ros::this_node::getName().c_str());
}
OpenRAVE::RobotBasePtr robot = env->GetRobot(robot_name);
if (!robot) {
throw OPENRAVE_EXCEPTION_FORMAT("There is no robot named '%s'.",
robot_name.c_str(), OpenRAVE::ORE_InvalidArguments);
}
return boost::make_shared<BHTactileSensor>(env, robot, owd_namespace, link_prefix);
} else {
示例10: fullread
std::streamsize fullread(
std::istream& istr,
char* buf,
std::streamsize requested)
{
std::streamsize got;
std::streamsize total = 0;
istr.read(buf, requested); /*Flawfinder: ignore*/
got = istr.gcount();
total += got;
while(got && total < requested)
{
if(istr.fail())
{
// If bad is true, not much we can doo -- it implies loss
// of stream integrity. Bail in that case, and otherwise
// clear and attempt to continue.
if(istr.bad()) return total;
istr.clear();
}
istr.read(buf + total, requested - total); /*Flawfinder: ignore*/
got = istr.gcount();
total += got;
}
return total;
}
示例11: getAsString
void getAsString(std::string& out, std::istream& is)
{
std::getline(is, out, '\0');
if (is.fail()) {
throw ExceptionStack("getAsString", __FILE__, __LINE__);
}
}
示例12: deserialize
bool VehicleStateBasicLux::deserialize(std::istream& is, const IbeoDataHeader& dh)
{
const std::istream::pos_type startPos = is.tellg();
lock();
ibeo::readLE(is, m_timestamp);
ibeo::readLE(is, m_scanNumber);
ibeo::readLE(is, m_errorFlags);
ibeo::readLE(is, m_longitudinalVelocity);
ibeo::readLE(is, m_steeringWheeAngle);
ibeo::readLE(is, m_wheelAngle);
ibeo::readLE(is, m_reserved0);
ibeo::readLE(is, m_xPos);
ibeo::readLE(is, m_yPos);
ibeo::readLE(is, m_courseAngle);
ibeo::readLE(is, m_timeDiff);
ibeo::readLE(is, m_xDiff);
ibeo::readLE(is, m_yDiff);
ibeo::readLE(is, m_yaw);
ibeo::readLE(is, m_reserved1);
ibeo::readLE(is, m_currentYawRate);
ibeo::readLE(is, m_reserved2);
unlock();
return !is.fail()
&& ((is.tellg() - startPos) == this->getSerializedSize())
&& this->getSerializedSize() == dh.getMessageSize();}
示例13: skipVolume
int32_t skipVolume(std::istream& in, bool binary, size_t totalSize)
{
int32_t err = 0;
if (binary == true)
{
std::istream::pos_type pos = in.tellg();
qint64 newPos = totalSize * sizeof(T) + 1;
in.seekg(newPos, std::ios_base::cur); // Move relative to the current position
pos = in.tellg();
if (in.fail())
{
// check if the position to jump to is past the end of the file
return -1;
}
}
else
{
T tmp;
for (size_t z = 0; z < totalSize; ++z)
{
in >> tmp;
}
}
return err;
}
示例14: readMoves
/**
* 手順の読み込み
*/
bool CsaReader::readMoves(std::istream& is, Record& record) {
char line[LINE_BUFFER_SIZE];
Move move;
while (true) {
is.getline(line, sizeof(line));
if (is.eof()) {
return true;
}
if (is.fail()) {
Loggers::warning << "file io error: " << __FILE__ << "(" << __LINE__ << ")";
return false;
}
if (readComment_(line) || readCommand_(line) || readTime_(line)) {
continue;
}
if (!readMove(line, record.getBoard(), move)) {
Loggers::warning << "invalid move format: " << __FILE__ << "(" << __LINE__ << ")";
Loggers::warning << "> " << line;
return false;
}
if (!record.makeMove(move)) {
Loggers::warning << "invalid move: " << __FILE__ << "(" << __LINE__ << ")";
Loggers::warning << "> " << line;
return false;
}
}
}
示例15: readBoard_
/**
* 局面の読み込み
*/
bool CsaReader::readBoard_(std::istream& is, Board& board, RecordInfo* info/* = nullptr*/) {
char line[LINE_BUFFER_SIZE];
board.init();
while (true) {
is.getline(line, sizeof(line));
if (is.eof()) {
break;
}
if (is.fail()) {
Loggers::warning << "file io error: " << __FILE__ << "(" << __LINE__ << ")";
return false;
}
if (!readBoard_(line, board, info)) {
Loggers::warning << "invalid board format: " << __FILE__ << "(" << __LINE__ << ")";
return false;
}
if (line[0] == '+' || line[0] == '-') {
break;
}
}
assert(board.getBKingSquare() != Square::Invalid);
assert(board.getWKingSquare() != Square::Invalid);
return true;
}