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


C++ istream::clear方法代码示例

本文整理汇总了C++中istream::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ istream::clear方法的具体用法?C++ istream::clear怎么用?C++ istream::clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在istream的用法示例。


在下文中一共展示了istream::clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

bool Point3Dot::load(istream &in){
  coords.resize(3);
  int start = in.tellg();
  for(int i = 0; i < 3; i++){
    in >> coords[i];
    if(in.fail()){
      in.clear();
      in.seekg(start+1); //????????? Why that one
      return false;
    }
  }
  in >> theta;
  if(in.fail()){
    in.clear();
    in.seekg(start+1); //????????? Why that one
    return false;
  }
  in >> phi;
  if(in.fail()){
    in.clear();
    in.seekg(start+1); //????????? Why that one
    return false;
  }
  int typeInt;
  in >> typeInt;
  type = (Type)typeInt;
  if(in.fail()){
    in.clear();
    in.seekg(start+1); //????????? Why that one
    return false;
  }
  return true;
}
开发者ID:contaconta,项目名称:neurons,代码行数:33,代码来源:Point3Dot.cpp

示例2: receive

bool Order::receive(istream& is){
	bool error = false;
	int a = 0;
	while (!error){
		cout << "Quantity (0  to quit): ";
		is >> a;
		is.clear();
		is.ignore();
		if (!is){
			is.clear();
			is.ignore(2000, '\n');
			cerr << "Error try again" << endl;
		}else if (a == 0){
			error = true;
			cerr << "No delivery recorded" << endl;
			return false;
		}else if (a < 0){
			cerr << "Please enter positive value" << endl;
		}
		else if (a > qtyOrder){
			cerr << a << " not on order.  Only " << qtyOrder << " are on order.  Try again" << endl;
		}else{
			qtyDeliver = qtyDeliver + a;
			return true;
		}
	}
}
开发者ID:Cohaven,项目名称:bookstore,代码行数:27,代码来源:Order.cpp

示例3: flushinput

// clears the file input buffer
void fileHandler::flushinput(istream & is)	{
	is.clear();
	char nextChar;
	while( (nextChar = is.get()) != '\n' && nextChar != EOF)
	{ }
	is.clear();
}
开发者ID:BeauJoh,项目名称:ppm,代码行数:8,代码来源:filehandler.cpp

示例4: setFromKeyboardByName

void Employee::setFromKeyboardByName(istream& in)
{
	string EGN;

	in >> EGN;
	while (!validateEGN(EGN))
	{
		in.clear();
		in.ignore(10000, '\n');
		in >> EGN;
	}
	this->EGN = EGN;

	in.clear();
	in.ignore(1);
	string address;
	getline(in, address);
	this->address = address;

	string hiredWhen;
	getline(in, hiredWhen);
	this->hiredWhen = hiredWhen;

	string boss;
	getline(in, boss);
	this->boss = boss;

	string projectName;
	getline(in, projectName);
	this->projectName = projectName;
}
开发者ID:TAPATOP,项目名称:Human-Resources,代码行数:31,代码来源:Employee.cpp

示例5: read

int FixedLengthBuffer::read(istream& stream){
	int recAddr = stream.tellg();
	stream.clear();
	this->clear();
	this->packing = 0; //FALSE
	stream.read(this->buffer, this->bufferSize);
	if(!stream.good()){
		stream.clear();
		return recAddr;
	}
	return recAddr;
}
开发者ID:oscarcp777,项目名称:tpfontela,代码行数:12,代码来源:FixedLengthBuffer.cpp

示例6: set

void Employee::set(istream& in, ostream& out)
{
	string name;
	in.clear();
	in.ignore(1);
	while (true)
	{
		getline(in, name);
		if (validateName(name))
		{
			this->name = name;
			break;
		}
		out << "Try again..." << endl;
	}

	string EGN;


	while (true)
	{
		in >> EGN;
		if (!validateEGN(EGN))
		{
			out << "Inavlid EGN" << endl;
			continue;
		}
		break;
	} 

	this->EGN = EGN;

	in.clear();
	in.ignore(1);
	string address;
	getline(in, address);
	this->address = address;

	string hiredWhen;
	getline(in, hiredWhen);
	this->hiredWhen = hiredWhen;

	string boss;
	getline(in, boss);
	this->boss = boss;

	this->position = (Position)0;

	string projectName;
	getline(in, projectName);
	this->projectName = projectName;
}
开发者ID:TAPATOP,项目名称:Human-Resources,代码行数:52,代码来源:Employee.cpp

示例7: ReadComplexElement

// no skip of WS
const string ReadComplexElement(istream& is)
{
  SkipWS( is);
  
  string buf;
  char c = is.get();
  if ( (is.rdstate() & ifstream::failbit ) != 0 )
    {
      if ( (is.rdstate() & ifstream::eofbit ) != 0 )
	throw GDLIOException( "End of file encountered. "+
			    StreamInfo( &is));
      if ( (is.rdstate() & ifstream::badbit ) != 0 )
	throw GDLIOException( "Error reading stream. "+
			    StreamInfo( &is));
      
      is.clear();
      return buf;
    }
  
  bool brace = (c == '(');

  if( !brace)
    {
      is.unget();
      return ReadElement( is);
    }

  buf.push_back( c);
  for(;;)
    {
      c = is.get();
      
      if ( (is.rdstate() & ifstream::failbit ) != 0 )
	{
	  if ( (is.rdstate() & ifstream::badbit ) != 0 )
	    throw GDLIOException( "Error reading line. "+
				StreamInfo( &is));
	  
	  is.clear();
	  return buf;
	}

      if( c == '\n') 
	return buf;

      buf.push_back( c);

      if( c == ')') 
	return buf;
    }
}
开发者ID:cenit,项目名称:GDL,代码行数:52,代码来源:default_io.cpp

示例8: fill_vector

// EOFまたは終了インジゲータが検出されるまでistからvに整数を読み取る
void fill_vector(istream& ist, vector<int>& v, char terminator){
	int i = 0;
	while(ist >> i) v.push_back(i);
	if(ist.eof()) return;		// OK: EOFが検出された

	if(ist.fail()){				// できるだけ後始末をし、問題を報告する
		ist.clear();			// ストリームの状態をクリアし、終了インジゲータを調査できるようにする
		char c;
		ist >> c;				// 文字を読み取る(終了インジゲータでありますように)
		if(c != terminator){	// 予想外の文字
			ist.unget();
			ist.clear(ios_base::failbit);	// 状態をfailに設定する
		}
	}
开发者ID:k-mi,项目名称:Stroustrup_PPP,代码行数:15,代码来源:10_6_2.cpp

示例9: read

void Point::read(istream& is)
{  char ch;
   is >> ch;
   if (is.fail()) return;
   if (ch != '(') { is.clear(ios::failbit); return; }
   is >> _x;
   is >> ch;
   if (is.fail()) return;
   if (ch != ',') { is.clear(ios::failbit); return; }
   is >> _y;
   is >> ch;
   if (is.fail()) return;
   if (ch != ')') { is.clear(ios::failbit); return; }
}
开发者ID:schulzmarc,项目名称:Loyola-University-Chicago---Computer-Science-272--Student-,代码行数:14,代码来源:shapes.cpp

示例10: GetString

	int GetString(string&strFound,istream&ifs)
	{
		strFound =  "";
		DFAEdge*ptDfa = &dfa;
		set<DFAEdge>::iterator edgeIt;
		int iChr;
		//skip leading WS
		while (true)
		{
			iChr=ifs.peek();
			if  (iChr == char_traits<char>::eof())
			{
				ifs.clear();
				break;
			}
			switch (iChr)
			{
				case '\r':
				case '\n':
				case '\t':
				case ' ':
					ifs.get();
					continue;
			}
			break;
		}
		while (true)
		{
			char ch;
			if ((iChr=ifs.peek()) == char_traits<char>::eof())
			{
				ifs.clear();
				ch = '\0';
			}
			else
			{
				ch = (char)iChr;
			}
			edgeIt = ptDfa->edges.find(ch);
			if (edgeIt == ptDfa->edges.end())
			{
				return ptDfa->id;
			}
			strFound += ch;
			ifs.get();
			ptDfa = &(*edgeIt);
		}
		return 0;
	}
开发者ID:nacitar,项目名称:old-projects,代码行数:49,代码来源:main.cpp

示例11: getCoord

//---------------------------------------------------------------------------------
// Function:	getCoord()
// Title:	Get Coordinates 
// Description:
//		Returns a cell with coordinates set by user
// Programmer:	Paul Bladek
// 
// Date:	9/12/06
//
// Version:	1.0
// 
// Environment: Hardware: i3 
//              Software: OS: Windows 7; 
//              Compiles under Microsoft Visual C++ 2012
//
// Input:	cell coordinates (in the form "A13" from sin
//
// Output:	prompts to cout
//
// Calls:	none
//
// Called By:	main()
//		setships()
//
// Parameters:	sin: istream&;	the stream to read from
//		size: char;	'S' or 'L'
// 
// Returns:	Cell location -- a cell containing the input coordinates
//
// History Log: 
//				9/12/06 PB comleted v 1.0
//				1/20/15 KG % HN completed v 1.1
//     
//---------------------------------------------------------------------------------
Cell getCoord(istream& sin, char size)
{
	cin.clear();
	fflush(stdin);
	short numberOfRows = (toupper(size)=='L') ? LARGEROWS : SMALLROWS;
	short numberOfCols = (toupper(size)=='L') ? LARGECOLS : SMALLCOLS;
	char highChar = static_cast<char>(numberOfRows - 1) + 'A';
	char row  = 'A';
	short col = 0;
	Cell location = {0, 0};
	do
	{
		col = 0;
		cout << "Row must be a letter from A to " << highChar 
			<< " and column must be  from 1 to "  << numberOfCols << ": ";
		while((row = toupper(sin.get())) < 'A' || row  > highChar)
		{
			sin.ignore(BUFFER_SIZE, '\n');
			cout << "Row must be a letter from A to " << highChar 
				<< " and column must be  from 1 to "  << numberOfCols << ": ";
		}
		sin >> col;
		if(!sin)
			sin.clear();
		sin.ignore(BUFFER_SIZE, '\n');
	}
	while(col < 1 || col > numberOfCols);
	location.m_col = col - 1;
	location.m_row = static_cast<short>(row - 'A');
	return location;
}
开发者ID:KyleGraham,项目名称:CS132,代码行数:65,代码来源:fleet.cpp

示例12: run

void run(exploder & e, istream& in)
{
   // any larger, and we may try to write to a multi_frame that never has enough space
   static const int BUF_SIZE = multi_frame::MAX_SIZE - frame::FRAME_SIZE;
   scoped_array<char> buffer(new char[BUF_SIZE]);

   ios::sync_with_stdio(false); // makes a big difference on buffered i/o

   for (int line = 1; !in.eof(); ++line)
   {
      in.getline(buffer.get(), BUF_SIZE - 1); // leave 1 for us to inject back the newline
      if (buffer[0] == '\0')
         continue;
      if (in.fail()) // line was too long?
      {
         cerr << "Skipping line <" << line << ">: line is probably too long" << endl;
         in.clear(); // clear state
         in.ignore(numeric_limits<streamsize>::max(), '\n');
         continue;
      }
      buffer[in.gcount() - 1] = '\n'; // inject back the newline
      buffer[in.gcount()] = '\0';
      e << buffer.get();
   }
}
开发者ID:kyle-johnson,项目名称:spread,代码行数:25,代码来源:explode_app.cpp

示例13: while

//---------------------------------------------------------------------------
unique_ptr<Expression> ExpressionParser::parseSingleExpression(istream& input, ExpressionType lastExpression, Environment& environment)
{
   // read
   harriet::skipWhiteSpace(input);
   char a = input.get();
   if(!input.good())
      return nullptr;

   // other single letter operators
   if(a == '(') return make_unique<OpeningPharentesis>();
   if(a == ')') return make_unique<ClosingPharentesis>();
   if(a == '+') return make_unique<PlusOperator>();
   if(a == '-') { if(lastExpression==ExpressionType::TBinaryOperator || lastExpression==ExpressionType::TUnaryOperator || lastExpression==ExpressionType::TOpeningPharentesis) return make_unique<UnaryMinusOperator>(); else return make_unique<MinusOperator>(); }
   if(a == '*') return make_unique<MultiplicationOperator>();
   if(a == '/') return make_unique<DivisionOperator>();
   if(a == '%') return make_unique<ModuloOperator>();
   if(a == '^') return make_unique<ExponentiationOperator>();
   if(a == '&') return make_unique<AndOperator>();
   if(a == '|') return make_unique<OrOperator>();
   if(a=='>' && input.peek()!='=') return make_unique<GreaterOperator>();
   if(a=='<' && input.peek()!='=') return make_unique<LessOperator>();
   if(a=='!' && input.peek()!='=') return make_unique<NotOperator>();
   if(a=='=' && input.peek()!='=') return make_unique<AssignmentOperator>();

   // check for string
   char b = input.get();
   if(a=='"') {
      string result;
      while(b!='"' && a!='\\') {
         if(!input.good())
            throw harriet::Exception{"unterminated string expression"};
         result.push_back(b);
         a = b;
         b = input.get();
      }
      return make_unique<StringValue>(result);
   }

   // check for two signed letters
   if(input.good()) {
      if(a=='=' && b=='=') return make_unique<EqualOperator>();
      if(a=='>' && b=='=') return make_unique<GreaterEqualOperator>();
      if(a=='<' && b=='=') return make_unique<LessEqualOperator>();
      if(a=='!' && b=='=') return make_unique<NotEqualOperator>();
      input.unget();
   } else {
      input.clear();
   }

   // check for a number
   input.unget();
   if(isdigit(a)) {
      int32_t intNum;
      input >> intNum;
      if(input.peek()=='.' && input.good()) {
         float floatNum;
         input >> floatNum;
         return make_unique<FloatValue>(floatNum+intNum);
      } else {
         return make_unique<IntegerValue>(intNum);
开发者ID:alexandervanrenen,项目名称:Harriet,代码行数:61,代码来源:ExpressionParser.cpp

示例14: load

void Frond::load(FrondGroup *group, istream &in)
{
	string line;
	float x, y;

	in >> x;
	in >> y;

	move(coord_t(x, y));

	setEnable(true);

	for(;;) {
		int id = -1;

		in >> id;

		if (!in.good() || id == -1) {
			in.clear();
			break;
		}

		Frond *p = group->getFrond(id);

		if (p == NULL) {
			p = new Frond(id, NULL);
			group->addFrond(p);
		}

		addPeer(p);
	}
}
开发者ID:jsgf,项目名称:frond,代码行数:32,代码来源:Frond.C

示例15: receive

/*
 * A modifier that receives a reference to an istream object 
 * and records receipt of copies based upon data from the input stream
 */
int Order::receive(istream& is){
    bool flag = false;
    bool continueGoing = true; 
    bool isChanged = false;
    int iStream;
 
    while (continueGoing){
        cout << "Quantity (0 to quit) : ";
        is >> iStream;
        if (!is) {
            is.clear();
            is.ignore(2000, '\n');
            cerr << "Error. Try Again " << endl;
        }
        else if (iStream == 0){
            continueGoing = false;
        }
        else if (iStream < 0){
            cerr << "Positive value only. Try again." << endl;
        }
        else if (iStream > ordered){
            cerr << iStream << " not on order. Only " << ordered << " are on order. Try again. " << endl;
        }
        else{
            delivered = delivered + iStream;
            isChanged = true;
            continueGoing = false;
        }
         
    }
    if (isChanged) 
        flag = true;
    return flag;
}
开发者ID:hellodarren,项目名称:isbn-reader,代码行数:38,代码来源:Order.cpp


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