本文整理汇总了C++中std::stringstream::fail方法的典型用法代码示例。如果您正苦于以下问题:C++ stringstream::fail方法的具体用法?C++ stringstream::fail怎么用?C++ stringstream::fail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::stringstream
的用法示例。
在下文中一共展示了stringstream::fail方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadVertex
bool ObjLoader::ReadVertex(const FaceMode& mode, const VertexData& verts, const size_t index) {
if (file.fail()) {
std::cout << "wtf?";
}
while(true) {
char c;
file.get(c);
if (whitespace(c))
continue;
file.unget();
if (file.fail()) {
std::cout << "wtf?";
}
if (newline(c))
return false;
break;
}
verts.positions[index] = readindex(positionCount);
if (mode.PositionsOnly)
return true;
file.ignore(1);
if (!mode.NoTextures)
verts.textures[index] = readindex(textureCount);
if (!mode.NoNormalSlash)
file.ignore(1);
if (!mode.NoNormals)
verts.normals[index] = readindex(normalCount);
return true;
}
示例2: readVals
// helper function to read input data files
bool readVals(std::stringstream &s, const int numvals, float * values) {
for (int i = 0 ; i < numvals ; i++) {
s >> values[i] ;
if (s.fail()) {
std::cout << "Failed reading value " << i << " will skip\n" ;
return false ;
}
}
return true ;
}
示例3: readvals
bool readvals(std::stringstream &s, const int numvals, std::vector<float> &values) {
for (int i = 0; i < numvals; i++) {
float f;
s >> f;
if (s.fail()) {
//cout << "Failed reading value " << i << " will skip\n";
return false;
}
values.push_back(f);
}
return true;
}
示例4: defined
void
print_stderr(std::stringstream& aStr)
{
#if defined(ANDROID)
// On Android logcat output is truncated to 1024 chars per line, and
// we usually use std::stringstream to build up giant multi-line gobs
// of output. So to avoid the truncation we find the newlines and
// print the lines individually.
char line[1024];
while (!aStr.eof()) {
aStr.getline(line, sizeof(line));
if (!aStr.eof() || strlen(line) > 0) {
printf_stderr("%s\n", line);
}
if (aStr.fail()) {
// line was too long, skip to next newline
aStr.clear();
aStr.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
}
#else
printf_stderr("%s", aStr.str().c_str());
#endif
}
示例5: while
std::vector<Element> parse_expression(std::stringstream &stream) {
std::vector<Element> out_buffer;
std::stack<Element> st;
while(stream.good()) {
char c = stream.peek();
assert(!stream.fail());
if(c == ')' || c == ']') {
stream.get();
while (1) {
assert(!st.empty());
Element element = st.top();
st.pop();
if(element.type == Element::Type::BRACKET) {
break;
} else {
out_buffer.push_back(convert_operator(element));
}
}
if(!st.empty() && st.top().type == Element::Type::FUNCTION) {
out_buffer.push_back(st.top());
st.pop();
}
} else if(c == '(' || c == '[') {
stream.get();
Element element { Element::Type::BRACKET };
#ifdef DEBUG_MATH_PARSER
element.identifier = "(";
#endif
st.push(element);
} else if(isalpha(c)) {
Element element;
std::string id = parse_identifier(stream);
#ifdef DEBUG_MATH_PARSER
element.identifier = id;
#endif
if(function_info.find(id) != function_info.end()) {
element.type = Element::Type::FUNCTION;
element.function = function_info[id];
st.push(element);
} else {
assert(id.length() == 1);
element.type = Element::Type::VARIABLE;
element.variable = id[0];
out_buffer.push_back(element);
}
} else if(isnumber(c)) {
Element element { Element::Type::SCALAR };
stream >> element.scalar;
out_buffer.push_back(element);
} else if(operator_info.find(c) != operator_info.end()) {
Element current { Element::Type::OPERATOR };
#ifdef DEBUG_MATH_PARSER
current.identifier = std::string(1, c);
#endif
current.op = operator_info[stream.get()];
while(!st.empty() && st.top().type == Element::Type::OPERATOR &&
st.top().op.precedence + st.top().op.rtl_associativity <= current.op.precedence) {
out_buffer.push_back(convert_operator(st.top()));
st.pop();
}
st.push(current);
} else if(isspace(c)) {
stream.get();
}
}