当前位置: 首页>>代码示例>>C++>>正文


C++ stringstream::fail方法代码示例

本文整理汇总了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; 
}
开发者ID:iadler221,项目名称:Graphics,代码行数:12,代码来源:scene.cpp

示例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; 
}
开发者ID:khashz,项目名称:Projects,代码行数:14,代码来源:Parser.cpp

示例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;
}
开发者ID:halftan,项目名称:practice,代码行数:11,代码来源:scene.cpp

示例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;
}
开发者ID:khashz,项目名称:Projects,代码行数:13,代码来源:Parser.cpp

示例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;
        }
    }
}
开发者ID:otaku690,项目名称:GPU-Pathtracer,代码行数:12,代码来源:fileParser.cpp

示例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;
}
开发者ID:achieverForever,项目名称:Raytracer,代码行数:13,代码来源:ReadFile.cpp

示例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;
} 
开发者ID:khashz,项目名称:Projects,代码行数:27,代码来源:Parser.cpp

示例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;
	}
开发者ID:velazqua,项目名称:competitive-programming,代码行数:16,代码来源:112.cpp

示例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";
}
开发者ID:kwonhong,项目名称:ECE244,代码行数:20,代码来源:ShapeArray.cpp

示例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";
}
开发者ID:kwonhong,项目名称:ECE244,代码行数:23,代码来源:ShapeArray.cpp


注:本文中的stringstream::fail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。