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


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

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


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

示例1: setTemplate

/******************************************************
 * Mutator function for member variable theTemplate.
 * 
 * Parameter: 
 *   theTemplate - 2D vector of doubles to set as theTemplate
**/
void KNearest::setTemplate(string fileName)
{
  Scanner scan;
  ReadData readData;

  scan.openFile(fileName);
  this->theTemplate = readData.readTemplate(scan);

  scan.close();
} // void setTemplate(vector< vector<double> > theTemplate)
开发者ID:L13HolyUmbra,项目名称:CSCE350_FinalProject,代码行数:16,代码来源:KNearest.cpp

示例2: setQuery

/******************************************************
 * Mutator function for member variable theQuery.
 * 
 * Parameter:
 *   theQuery - a vector<double> to set as theQuery
**/
void KNearest::setQuery(string fileName)
{
  Scanner scan;
  ReadData readData;

  scan.openFile(fileName);
  this->theQuery = readData.readQuery(scan);

  scan.close();
} // void setQuery(vector<double> theQuery)
开发者ID:L13HolyUmbra,项目名称:CSCE350_FinalProject,代码行数:16,代码来源:KNearest.cpp

示例3: 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

示例4: main

int main(int argc, char *argv[])
{ string timeCallOutput = "";
  string inFileName = "";
  string outFileName = "";
  string logFileName = "";
  ifstream inStream;
  ofstream outStream;
    
  Scanner inScanner;
  
    
  ///////////////////////////////////////////////////////////////
  // Boilerplate for opening files
  Utils::CheckArgs(3, argc, argv, "infilename outfilename logfilename");
  inFileName = (string) argv[1];
  outFileName = (string) argv[2];
  logFileName = (string) argv[3];
    
  Utils::FileOpen(outStream, outFileName);
  Utils::LogFileOpen(logFileName);
    
  timeCallOutput = Utils::timecall("beginning");
  Utils::logStream << timeCallOutput;
  Utils::logStream << TAG << "Beginning execution" << endl;
  Utils::logStream.flush();
    
  Utils::logStream << TAG << "infile  '" << inFileName << "'" << endl;
  Utils::logStream << TAG << "outfile '" << outFileName << "'" << endl;
  Utils::logStream << TAG << "logfile '" << logFileName << "'" << endl;
  Utils::logStream.flush();
    
  ///////////////////////////////////////////////////////////////
  // The actual work part of the main program
  inScanner.openFile(inFileName);
  
    
  ///////////////////////////////////////////////////////////////
  // Boilerplate for closing up
  Utils::logStream << TAG << "Ending execution" << endl;
  timeCallOutput = Utils::timecall("ending");
  Utils::logStream << timeCallOutput;
  Utils::logStream.flush();
  
  Utils::FileClose(outStream);
  Utils::FileClose(Utils::logStream);
    
  return 0;
}
开发者ID:greatdave94,项目名称:codesamples,代码行数:48,代码来源:Main.cpp

示例5: TestScanner

// was used to test the scanner
int TestScanner(  string argv ) // int TestScanner(  int argc, char* argv[] )
{
	// name of the file to parse through
	std::string fName = argv;

	Scanner* dispatcher = new Scanner();
	dispatcher->openFile(fName);

	// Adjusted to print tokens to text file
	std::ofstream out("tokens.txt");
    std::streambuf *coutbuf = std::cout.rdbuf();	//save old buffer
    std::cout.rdbuf(out.rdbuf());					//redirect std::cout to tokens.txt


	// Adjusted to print in the proper order
	cout << setw(15) << left << "Token" << setw(8) << "Line #" << setw(10) << "Column #" << setw(45) << "Lexeme"<< endl;	 
	while (dispatcher->hasToken())
	{
		 //Keep on separate couts so that getToken() executes first
		cout << setw(15) << left << EnumToString(dispatcher->getToken()); //set the token	
			cout << setw(8) << dispatcher->getLineNumber() << setw(10) << dispatcher->getColumnNumber();

		if (dispatcher->getLexeme().size() > 45){
			string temp;
			temp = dispatcher->getLexeme().substr(0,44);
			cout << temp << endl;

		} else
			cout << dispatcher->getLexeme()<< endl;
	}

	cout << setw(15) << left << EnumToString(dispatcher->getToken()) 
		<< setw(8) << dispatcher->getLineNumber() << setw(10) << dispatcher->getColumnNumber() 
		<< setw(45) << dispatcher->getLexeme() << endl << endl;

	std::cout.rdbuf(coutbuf);						//reset to standard output

	// press enter to exit
	printf("Done. Press Enter to exit.\n");
	cin.get();
	return 0;
}
开发者ID:JonDub,项目名称:CSCI.468-Compilers,代码行数:43,代码来源:mp.cpp

示例6: main

int main(int argc, char** varg)
{
  if(argc < 4)//this is how to use this
  {
    cerr << "usage: cmd file1 file2 output" << endl;
    return 1;
  }

  //these are for holding each files occurances of strings, or lack thereof
  set<WORD> file1, file2;
  
  //Java like Scanner object
  Scanner scan;
  //open the file given as argument 1
  scan.openFile(varg[1]);
  //to the first file 'file1' we will add each string that is in there
  //for the first occurance we set count at 1, and increment as needed
  //to the second file 'file2' we will add each string from 'file1'
  //and set the count to 0
  while(scan.hasMoreData())
  {
    ScanLine line;
    line.openString(scan.nextLine());
    while(line.hasMoreData())
    {
      string nxt_token = line.next();
      nxt_token = Utils::trimBlanks(nxt_token);

      //add elements to 'file2' once with count 0
      if(file2.count(nxt_token) == 0)
      {
	WORD f_two;
	f_two.token = nxt_token;
	f_two.count = 0;
        file2.insert(f_two);
      }
      //add first occurance to file1 with count 1
      if(file1.count(nxt_token) == 0)
      {
	WORD f_one;
	f_one.token = nxt_token;
	f_one.count = 1;
        file1.insert(f_one);
      }
      else
      {
	//replace the word with a word of equal token and +1 count
	set<WORD>::iterator it = file1.find(WORD(nxt_token));
	int ct = it->count;
	ct++;
	file1.erase(it);
	WORD replace;
	replace.token = nxt_token;
	replace.count = ct;
	file1.insert(replace);
      }
    }
  }
  scan.close();//close file1

  cout << "++++++++++++++++++++++++++++++++++++++++++++++++" << endl;

  scan.openFile(varg[2]);//open file2

  //to the second file 'file2' we will add each word we find, or
  //increment as needed if it occurred in the first file
  //if a string occurs in 'file2' that doesn't exist in 'file1'
  //we will add any token to 'file1' list from 'file2' list and set count to 0
  while(scan.hasMoreData())
  {
    ScanLine line;
    line.openString(scan.nextLine());
    while(line.hasMoreData())
    {
      string nxt_token = line.next();
      nxt_token = Utils::trimBlanks(nxt_token);
      
      //if the word doesn't already exist in 'file1' add it with count 0
      if(file1.count(nxt_token) == 0)
      {
	WORD f_two;
	f_two.token = nxt_token;
	f_two.count = 0;
        file1.insert(f_two);
      }
      //add the first occurance of a word to 'file2' with count 1
      if(file2.count(nxt_token) == 0)
      {
	WORD f_one;
	f_one.token = nxt_token;
	f_one.count = 1;
        file2.insert(f_one);
      }
      else
      {
	//replace the word with a word of equal token and +1 count	
	set<WORD>::iterator it = file2.find(WORD(nxt_token));
	int ct = it->count;
	ct++;
	file2.erase(it);
//.........这里部分代码省略.........
开发者ID:bflick,项目名称:ocrcomp,代码行数:101,代码来源:Compare.cpp


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