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


C++ Scanner::hasNext方法代码示例

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


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

示例1: readData

/******************************************************************************
In the readData() we are simply inputting the "xintput.txt" file in a vector. 
we create a object for Scanner class and use a While loop to continuously scan
for text in the file until it has nothing else in it. While the scanner is 
reading in the values this data is now pushed back into a vector called TheData.
We now have a vector that consist of 100 values of stock and it now received.


****/
void MovingAverage::readData(std::string fileName)
{
Scanner inScanner;
double value ;
inScanner.openFile(fileName);
std::cout << "Now receiving Stocks" << std::endl;

  while(inScanner.hasNext())
  {
    value = inScanner.nextDouble(); 
    theData.push_back(value);  
  }
  
 
}
开发者ID:USCDMProjects,项目名称:Stock-Market-Excercise,代码行数:24,代码来源:MovingAverage.cpp

示例2: runForever

/******************************************************************************
 * Function 'runForever' 
 * This function will do most of the programs work. It will take in all the packets
 * (which realistically, should make this a continuously running function) and call
 * the function for them to be read. It will take these read packets and add them to
 * messages and then add these messages to the  MessagesMap. It will test if a message
 * has been completed upon the addition of a packet and call the messageDump function 
 * to remove and output a message if it is done. In the scale of this program, this function
 * runs until all the messages are complete and there are no more packets to take in.
 *
 * Parameters:
 * scanner - the 'Scanner' from which to read 
 * outStream - the stream to which to write
 *
 * Returns: None
 *
 * Output: Adds each completed message to the OutStream. 
**/
void PacketAssembler::runForever(Scanner& scanner, ofstream& outStream)
{
#ifdef EBUG
  Utils::logStream << "enter runForever\n"; 
#endif

  Packet tempPacket; 
  int tempMessageID; 
  
  //run as long as there are more packets to take in. 
  while(scanner.hasNext()) 
  {
    //create a temporary packet and call the read from the Packet class to assign it values
    tempPacket = Packet(scanner);
    tempMessageID = tempPacket.getMessageID(); 
    //using this packets MessageID, check if we already have this message
    if (messagesMapContains(tempMessageID) == false)
    {
      //if not create a new Message and push it into the messagesMap
      Message tempMessage;
      tempMessage.insert(tempPacket); 
      messagesMap.insert(std::pair<int, Message>(tempMessageID, tempMessage));   
    } 
   
    //otherwise, this message is in the Messages map and we should just add the new
    //packet to the message already in the messages map. 
    else 
    {
      if(messagesMapContains(tempMessageID))
      {
        messagesMap[tempMessageID].insert(tempPacket); 
      }
    }  
  
    //after adding each packet, we should check if that packet completed a message
    if (messagesMap[tempMessageID].isComplete() == true)
    {
      //if it did, dump it and outStream the data. 
      outStream << "The Completed message is: ";
      outStream << "\n";  
      outStream << dumpMessage(tempMessageID); 
    }
  } 

#ifdef EBUG
  Utils::logStream << "leave runForever\n"; 
#endif
}
开发者ID:L13HolyUmbra,项目名称:CSCE240_Homework6,代码行数:66,代码来源:PacketAssembler.cpp


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