本文整理汇总了C++中stringstream::fail方法的典型用法代码示例。如果您正苦于以下问题:C++ stringstream::fail方法的具体用法?C++ stringstream::fail怎么用?C++ stringstream::fail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stringstream
的用法示例。
在下文中一共展示了stringstream::fail方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readvals
// Function to read the input data values
// Use is optional, but should be very helpful in parsing.
bool Scene::readvals(stringstream &s, const int numvals, float *values) {
for (int i = 0 ; i < numvals ; i++) {
s >> values[i];
if (s.fail()) {
cout << "Failed reading value " << i << " will skip\n";
return false;
}
}
return true;
}
示例2: get_label
// this statement is different than the get_alllabel becuase this just reads
// in a string, it does not not check for the inputted string's value
// the use of this occurs in the changeR and find commands
string get_label (stringstream &ss){
string character;
ss >> character;
// this check tells us if an input was read
if (ss.fail())
{
cout << "Error: missing argument" << endl;
return "errrrrrrrrrrrrrrrrrrror";
}
return character;
}
示例3: readvals
bool raytr::readvals(stringstream &s, const int numvals, double *values)
{
for (int i = 0; i < numvals; ++i) {
s >> values[i];
if (s.fail()) {
cerr << "Failed reading value " << i << " skips this line." << endl;
return false;
}
}
return true;
}
示例4: get_extra
// this function was created to test if more then the desired amount of inputs
// were inputted
int get_extra (stringstream &ss){
string i;
ss >> i;
//checks to see if it read an input
if (!(ss.fail()))
{
cout << "Error: too many arguments" << endl;
return 1;
}
return 0;
}
示例5: stringParse
bool stringParse( stringstream &s, const int numvals, string* str )
{
for( int i = 0; i < numvals; i++ )
{
s>>str[i];
if (s.fail())
{
cout << "Failed reading value " << i << " will skip\n";
return false;
}
}
}
示例6: ReadValues
bool ReadValues(stringstream & s, const int num, float * values)
{
for(int i = 0; i < num; i++)
{
s >> values[i];
if(s.fail())
{
cerr << "Failed Reading Values " << i << " Will Skip.\n";
return false;
}
}
return true;
}
示例7: get_resistance
// function for reading the resistance from the stringstream. While it reads the
// DOUBLE it tests 3 various errors that can arrive from the user
// I set an arbitrary return of -1 for an error occurrence so my function calls
// know if it failed, if not it returns the desired input
double get_resistance (stringstream &ss){
double i;
ss >> i;
// check for invalid number my making sure it was read, and also making sure
// if the stored type into the variable matches and also checks to make sure
// the input is not a double or if a character follows the integer
if ((ss.fail() && !(ss.eof()))){
cout << "Error: argument is not a number" <<endl;
return -1;
}
// checks to see if the resistance was negative
else if (i < 0.0){
cout << "Error: invalid resistance (negative)" << endl;
return -1;
}
// this check tells us if an input was read
else if (ss.fail())
{
cout << "Error: missing argument" << endl;
return -1;
}
return i;
}
示例8: treeTrace
bool treeTrace( stringstream &ss, vector<int> &T, int currSum )
{
if( ss.rdbuf()->in_avail() == 0 )
return false;
char leftBracket;
ss >> leftBracket;
int integer;
ss >> integer;
bool leftTree;
if( ss.fail() )
{
ss.clear();
char otherBracket;
ss >> otherBracket;
return false;
}
示例9: translate
void ShapeArray::translate (stringstream& linestream) {
string name;
float xShift, yShift, xShape, yShape;
linestream >> xShape >> yShape >> xShift >> yShift;
if (linestream.fail()) {
cout << "Error: invalid arguments\n";
return;
}
Shape* shape = findShape (xShape, yShape);
if (shape == NULL) {
cout << "Error: could not find shape at (" << xShape << ","
<< yShape << ")" << endl;
return;
}
shape->setXcen (shape->getXcen() + xShift);
shape->setYcen (shape->getYcen() + yShift);
cout << "Success\n";
}
示例10: scale
void ShapeArray::scale (stringstream& linestream) {
string name;
float scaleFac;
linestream >> name >> scaleFac;
if (linestream.fail()) {
cout << "Error: invalid arguments\n";
return;
}
if (scaleFac < 0) {
cout << "Error: scaling factor must be nonnegative\n";
return;
}
Shape* shape = findShape (name);
if (shape == NULL) {
cout << "Error: could not find shape with name " << name << endl;
return;
}
shape->scale (scaleFac);
cout << "Success\n";
}