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


C++ istream类代码示例

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


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

示例1: buildGraph

/* Function buildGraph
Takes a properly formatted text input and creates class data
Properly formatted definition
First line contains an int of the number of nodes
Followed by a number of lines equal to the first line with node descriptions
followed by any number of three int with space delimiters
ends with a termination string of 0 0
*/
void GraphL::buildGraph(istream& infile) {
   int fromNode, toNode;              // from and to node ends of edge

   makeEmpty();                       // clear the graph of memory 

   infile >> size;     // read the number of nodes

   if (infile.eof()) return;          // stop if no more data
   
   string s;                          // used to read through to end of line
   getline(infile, s);

   // read graph node information
   for (int i=1; i <= size; i++) {
      // read using setData of the NodeData class,
      // something like: 
      //    adjList[i].data.setData(infile);
      // where adjList is the array of GraphNodes and
      // data is the NodeData object inside of GraphNode
       if(i > MAXNODES-1) {
			getline(infile,s);
		}
	   data[i].setData(infile);
   }
   if(size > MAXNODES-1) {
       size = MAXNODES-1;
   }
   // read the edge data and add to the adjacency list
   for (;;) {
      infile >> fromNode >> toNode;
      if (fromNode ==0 && toNode ==0) return;     // end of edge data
	  insertEdge(fromNode, toNode);
      // insert the edge into the adjacency list for fromNode

   }
}
开发者ID:christran206,项目名称:EducationPrograms,代码行数:44,代码来源:graphl.cpp

示例2: readlist

void readlist (list<T> &mylist, istream &stream, bool &isunique) {
   try {
      for (;;) {
         try {
            string line;
            getline (stream, line);
            if (stream.eof() ) {
               break;
            }
            T elem = from_string<T> (line);
            if (isunique == true) {
               if ( !mylist.contains_elem (elem) ) mylist.push (elem);
            } else {
               mylist.push (elem);
            }
         } catch (list_exn exn) {
            // If there is a problem discovered in any function, an
            // exn is thrown and printed here.
            complain() << exn.what() << endl;
         }
      }
   } catch (list_exit_exn) {
   }
}
开发者ID:Masacs,项目名称:coursework,代码行数:24,代码来源:main.cpp

示例3: menu

// menu prompts for and accepts an option selection from standard input and
// returns the character identifying the selected option
//
char menu(istream& is) {
    char c;
    int  ok = false;

    cout << '\n';
    cout << "Please select from the following options :\n";
    cout << " P - Place an order with a publisher\n";
    cout << " S - Place a special order with a publisher\n";
    cout << " A - Add one copy to an existing order\n";
    cout << " D - Record a delivery from a publisher\n";
    cout << " V - View status of books on order\n";
    cout << " Q - Quit\n";
    do {
        cout << " Your selection : ";
        c = ' ';
        is.get(c);
        if (c >= 'a' && c <= 'z')
            c -= 'a' - 'A';
        if (is.fail()) {
            is.clear();
            is.ignore(2000, '\n');
            cerr << " Invalid input.  Try again." << endl;
        } else if (c == '\n') {
            ; // no input - try again
        } else if (c != 'P' && c != 'S' && c != 'A' && c != 'D' && c != 'V'
         && c != 'Q') {
            is.ignore(2000, '\n');
            cerr << " Invalid Character.  Try again." << endl;
        } else if (is.get() != '\n') {
            is.ignore(2000, '\n');
            cerr << " Trailing Characters.  Try Again. " << endl;
        } else if (c == 'P' || c == 'S' || c == 'A' || c == 'D' || c == 'V'
         || c == 'Q')
            ok = true;
    } while (ok == 0);

    return c;
}
开发者ID:shreyaspatel,项目名称:ISBN-Registration-Application,代码行数:41,代码来源:a4main.cpp

示例4: read_var_

void read_var_(istream& sf, int& fl, double& var, double* same_var, int& i)
{
  i = 0;
  double tmp = HUGE_VAL;
  sf >> ws;
  if (sf.peek() == '*')
  {
    fl = series::fixed;
    sf.ignore();
  }
  else if (sf.peek() == '#')
  {
    fl = series::same;
    sf.ignore();
    if (isdigit(sf.peek()))
    {
      sf >> i;
      if (i >= nvar) i = 0;
      sf.clear();
    }
开发者ID:Teslos,项目名称:tdlib00-,代码行数:20,代码来源:sumsqrin.cpp

示例5: read_poll

//Read the contents of a poll(gender, age, year, studies)
//Receives as parameter the stream from which it reads
Poll read_poll(istream& list_students) {
  char current_studies[SIZE];
  Poll current_poll;
  
  //Set gender as 1 if it is male and 0 otherwise
  current_poll.gender = (list_students.get() == 'M' ? 1 : 0);
  list_students.ignore(1); //Skip the ','
  
  list_students >> current_poll.age;
  list_students.ignore(1); //Skip the ','
  
  list_students.get(current_studies, SIZE, ',');
  current_poll.studies = string(current_studies);
  list_students.ignore(1); //Skip the ','
  
  list_students >> current_poll.year;
  list_students.ignore(1); //Skip the '\n'
  
  return current_poll;
}
开发者ID:angargo,项目名称:TuentiChallenge4,代码行数:22,代码来源:ch01.cpp

示例6: fillVector

void fillVector(vector<int> &v, istream &ist, char terminator)
{
	int x;
	while(ist >> x)
		v.push_back(x);
	if(ist.bad())
		error("Some unusual error occurred, stream is in bad state.");
	if(ist.eof())
		return;
	if(ist.fail()) {
		ist.clear();	// clear stream state
		char c;
		ist >> c;
		if(c == terminator) {
			cout << "found terminator\n";
			return;
		}
		ist.unget();
		ist.clear(ios_base::failbit);	// set the state to fail
	}
开发者ID:kaustubhb,项目名称:PPPCpp,代码行数:20,代码来源:fillvector.cpp

示例7: load

      void load(istream &in){

	 ulint w_size;

	 in.read((char*)&w_size,sizeof(w_size));

	 if(w_size>0){

	    words = vector<uint64_t>(w_size);
	    in.read((char*)words.data(),sizeof(uint64_t)*w_size);

	 }

	 in.read((char*)&psum_,sizeof(psum_));

	 in.read((char*)&MASK,sizeof(MASK));

	 in.read((char*)&size_,sizeof(size_));

	 in.read((char*)&width_,sizeof(width_));

	 in.read((char*)&int_per_word_,sizeof(int_per_word_));

      }
开发者ID:vgteam,项目名称:DYNAMIC,代码行数:24,代码来源:packed_vector.hpp

示例8: readFromStreamBinary

void ImagePatch::readFromStreamBinary(istream& in) {

	char hasData;// = (char)(data != NULL);
	char hasIntegralData;// = (char) (integralData!=NULL);
	int dataRowWidth;


	in.read((char*)&width, sizeof(int));
	in.read((char*)&height, sizeof(int));
	in.read((char*)&dataRowWidth, sizeof(int));
	in.read(&hasData,sizeof(char));
	if (hasData) {
		imgData.create(height, width, CV_8U);
		unsigned char* data = imgData.data;
		in.read((char*)data, height*imageDataRowBytes());
	}
	in.read(&hasIntegralData,sizeof(char));
	if (hasIntegralData) {
		intData.create(height+1, width+1, CV_32S);
		Size s = getIntegralSize();
		integral_type* integralData = (integral_type*) intData.data;
		in.read((char*)integralData,s.height*integralDataRowBytes());
	}
}
开发者ID:hansonrobotics,项目名称:HEAD,代码行数:24,代码来源:ImagePatch.cpp

示例9: applyFilter

void EndlineFilter::applyFilter(istream & inStream, ostream & outStream)
{
	while (inStream.good()) 
	{
		char currentLetter;
		currentLetter = inStream.get();
		while (inStream.good())
		{
			if (currentLetter != '\n')
			{
				outStream << currentLetter;
				currentLetter = inStream.get();
			}
			else
			{
				outStream << "<br>" << " ";
				currentLetter = inStream.get();
			}
		}
		inStream.unget();
	}
};
开发者ID:ShannonSimpson,项目名称:Text-File-to-HTML-Converter,代码行数:22,代码来源:EndlineFilter.cpp

示例10: load

	void load(istream &in){

		ulint encode_size;
		ulint decode_size;

		in.read((char*)&encode_size,sizeof(encode_size));
		in.read((char*)&decode_size,sizeof(decode_size));

		for(ulint i=0;i<encode_size;++i){

			char_type c;
			in.read((char*)&c,sizeof(c));

			vector<bool> B;
			load_vec_bool(in,B);

			encode_.insert({c,B});

		}

		for(ulint i=0;i<decode_size;++i){

			vector<bool> B;
			load_vec_bool(in,B);

			char_type c;
			in.read((char*)&c,sizeof(c));

			decode_.insert({B,c});

		}

		in.read((char*)&sigma,sizeof(sigma));

		in.read((char*)&log_sigma,sizeof(log_sigma));

		in.read((char*)&enc_type,sizeof(enc_type));

	}
开发者ID:nicolaprezza,项目名称:DYNAMIC,代码行数:39,代码来源:alphabet_encoder.hpp

示例11: ReadString

  static void ReadString (istream & ist, char * str)
  {
    //char * hstr = str;
    char ch;

    for (;;)
      {
	ist.get(ch);
	if (!ist.good()) break;

	if (!isspace (ch))
	  {
	    ist.putback (ch);
	    break;
	  }
      }

    for (;;)
      {
	ist.get(ch);
	if (!ist.good()) break;
	if (isalpha(ch) || isdigit(ch))
	  {
	    *str = ch;
	    str++;
	  }
	else
	  {
	    ist.putback (ch);
	    break;
	  }
      }
    *str = 0;
    //  cout << "Read string (" << hstr << ")" 
    //       << "put back: " << ch << endl;
  }
开发者ID:Resistancerus,项目名称:Netgen,代码行数:36,代码来源:solid.cpp

示例12: getFunctionInput

int getFunctionInput(istream &fin, FunctionFormat &function)
{
	function.prepUp();
	fin.ignore(numeric_limits<streamsize>::max(), ':');
	if(fin.eof())
		return 1; //Could not find a function
	fin>>function.newname;
	if(!fin)
		return 1; //There was nothing after colon
	while(fin)
	{
		int temp;
		fin>>temp;
		if(fin)
			function.addReturn(temp);
	}
	fin.clear();
	while(fin.peek()!=':' && !fin.eof())
	{
		char temp_string[1000];
		fin.getline(temp_string, 1000);
		stringstream case_string_stream(temp_string);
		Case temp_case;
		case_string_stream>>temp_case.oldname;
		while(case_string_stream)
		{		
			int temp_int;
			case_string_stream>>temp_int;
			if(case_string_stream)
				temp_case.addArg(temp_int);
		}
		
		function.addCase(temp_case);
	}
	return 0;
}
开发者ID:harpreetrathore,项目名称:scilab-IPT,代码行数:36,代码来源:migrate.cpp

示例13: readImpl

//---------------------------------------------------------------------------
void EclipseGridParser::readImpl(istream& is)
//---------------------------------------------------------------------------
{
    if (!is) {
        cerr << "Could not read given input stream." << endl;
        throw exception();
    }

    // Make temporary maps that will at the end be swapped with the
    // member maps
    // NOTE: Above is no longer true, for easier implementation of
    //       the INCLUDE keyword. We lose the strong exception guarantee,
    //       though (of course retaining the basic guarantee).
    map<string, vector<int> >& intmap = integer_field_map_;
    map<string, vector<double> >& floatmap = floating_field_map_;

    // Actually read the data
    std::string keyword;
    while (is.good()) {
        is >> ignoreWhitespace;
        bool ok = readKeyword(is, keyword);
        if (ok) {
            //#ifdef VERBOSE
            cout << "Keyword found: " << keyword << endl;
            //#endif
            FieldType type = classifyKeyword(keyword);
            // std::cout << "Classification: " << type << std::endl;
            switch (type) {
            case Integer: {
                readVectorData(is, intmap[keyword]);
                break;
            }
            case FloatingPoint: {
                readVectorData(is, floatmap[keyword]);
                break;
            }
            case Timestepping: {
                SpecialMap& sm = special_field_by_epoch_[current_epoch_];
                if (start_date_.is_not_a_date()) {
                    // Set it to START date, or default if no START.
                    // This will only ever happen in the first epoch,
                    // upon first encountering a timestepping keyword.
                    if (hasField("START")) {
                      start_date_ = getSTART().date;
                    } else {
                      start_date_ = boost::gregorian::date( 1983 , 1 , 1 );
                    }
                }
                if (current_reading_mode_ == Regular) {
                    current_reading_mode_ = Timesteps;
                }
                // Get current epoch's TSTEP, if it exists, create new if not.
                SpecialMap::iterator it = sm.find("TSTEP");
                TSTEP* tstep = 0;
                if (it != sm.end()) {
                    tstep = dynamic_cast<TSTEP*>(it->second.get());
                } else {
                    SpecialFieldPtr sb_ptr(new TSTEP());
                    tstep = dynamic_cast<TSTEP*>(sb_ptr.get());
                    sm["TSTEP"] = sb_ptr;
                }
                assert(tstep != 0);
                // Append new steps to current TSTEP object
                if (keyword == "TSTEP") {
                    const int num_steps_old = tstep->tstep_.size();
                    tstep->read(is); // This will append to the TSTEP object.
                    const double added_days
                        = std::accumulate(tstep->tstep_.begin() + num_steps_old, tstep->tstep_.end(), 0.0);
                    current_time_days_ += added_days;
                } else if (keyword == "DATES") {
                    DATES dates;
                    dates.read(is);
                    for (std::size_t dix = 0; dix < dates.dates.size(); ++dix) {
                        boost::gregorian::date_duration since_start = dates.dates[dix] - start_date_;
                        double step = double(since_start.days()) - current_time_days_;
                        tstep->tstep_.push_back(step);
                        current_time_days_ = double(since_start.days());
                    }
                } else {
                    OPM_THROW(std::runtime_error, "Keyword " << keyword << " cannot be handled here.");
                }
                break;
            }
            case SpecialField: {
                if (current_reading_mode_ == Timesteps) {
                    // We have been reading timesteps, but have
                    // now encountered something else.
                    // That means we are in a new epoch.
                    current_reading_mode_ = Regular;
                    special_field_by_epoch_.push_back(SpecialMap());
                    ++current_epoch_;
                    assert(int(special_field_by_epoch_.size()) == current_epoch_ + 1);
                    // Add clones of all existing special fields to new map.
                    SpecialMap& oldmap = special_field_by_epoch_[current_epoch_ - 1];
                    SpecialMap& newmap = special_field_by_epoch_[current_epoch_];
                    for (SpecialMap::iterator it = oldmap.begin(); it != oldmap.end(); ++it) {
                        // if (it->first != "TSTEP") {
                            newmap[it->first] = cloneSpecialField(it->first, it->second);
                            //}
//.........这里部分代码省略.........
开发者ID:karbor,项目名称:opm-core,代码行数:101,代码来源:EclipseGridParser.cpp

示例14: getDump

static bool getDump (istream&          ifile,
		     ostream&          ofile,
		     vector<Data2DF*>& u    )
// ---------------------------------------------------------------------------
// Read next set of field dumps from ifile, put headers on ofile.
// ---------------------------------------------------------------------------
{
  static char* hdr_fmt[] = { 
    "%-25s "    "Session\n",
    "%-25s "    "Created\n",
    "%-25s "    "Nr, Ns, Nz, Elements\n",
    "%-25d "    "Step\n",
    "%-25.6g "  "Time\n",
    "%-25.6g "  "Time step\n",
    "%-25.6g "  "Kinvis\n",
    "%-25.6g "  "Beta\n",
    "%-25s "    "Fields written\n",
    "%-25s "    "Format\n"
  };
  char  buf[StrMax], fmt[StrMax], fields[StrMax];
  int_t i, j, swab, nf, np, nz, nel;

  if (ifile.getline(buf, StrMax).eof()) return false;
  
  if (!strstr (buf, "Session")) message (prog, "not a field file", ERROR);
  ofile << buf << endl;
  ifile.getline (buf, StrMax);
  ofile << buf << endl;

  // -- I/O Numerical description of field sizes.

  ifile >> np >> nz >> nz >> nel;
  ifile.getline (buf, StrMax);
  
  sprintf (fmt, "%1d %1d %1d %1d", np, np, nz, nel);
  sprintf (buf, hdr_fmt[2], fmt);
  ofile << buf;

  for (i = 0; i < 5; i++) {
   ifile.getline (buf, StrMax);
   ofile << buf << endl;
  }

  // -- I/O field names.

  ifile >> fields;
  nf = strlen (fields);
  for (j = 0, i = 0; i < nf; i++) fmt[j++] = fields[i];
  fmt[j] = '\0';
  sprintf (buf, hdr_fmt[8], fmt);
  ofile << buf;
  ifile.getline (buf, StrMax);

  // -- Arrange for byte-swapping if required.

  ifile.getline (buf, StrMax);

  swab = doSwap (buf);

  sprintf (buf, "binary ");
  Veclib::describeFormat (buf + strlen (buf));
  sprintf (fmt, hdr_fmt[9], buf);
  ofile << fmt;

  if (u.size() != nf) {
    u.resize (nf);
    for (i = 0; i < nf; i++) u[i] = new Data2DF (np, nz, nel, fields[i]);
  }

  for (i = 0; i < nf; i++) {
    ifile >> *u[i];
    if (swab) u[i] -> reverse();
  }

  return ifile.good();
}
开发者ID:jueqingsizhe66,项目名称:MrWang,代码行数:76,代码来源:lowpass.C

示例15: readMesh

void 
readMesh  ( istream &is, chunkSize size,char *name )
{
	tab++;

	vector<Point> vertex;
	vector<TriangleIndex> triangle;

	while (1)
	{
		chunkSize subChunkSize = 0;
		chunkID   subChunkID = 0;

		if (!(subChunkID = readChunk(is,subChunkSize))) break;

		switch (subChunkID)
		{
		case 0x4110:						// Vertex List
			{
				unsigned short number;
				is.read((char *) (void *) &number,2);

				TAB(1);
				DOUT(1) << "vertex list: " << number << " points." << endl;

				char buffer[12];

				for (int n=0;n<number;n++)
				{
					is.read(buffer,12);
					vertex.push_back
					( 
						Point
						(
							Vector
							(
								*((float *) &buffer[0]),
								*((float *) &buffer[4]),
								*((float *) &buffer[8])
							),
							Vector0
						)

					);

					TAB(2);
					DOUT(2) << vertex.back() << endl;
				}
			}
			break;
		case 0x4120:						// Face List
			{
				unsigned short number;
				is.read((char *) (void *) &number,2);

				TAB(1);
				DOUT(1) << "face list: " << number << " faces." << endl;

				char buffer[8];

				for (int n=0;n<number;n++)
				{
					is.read(buffer,8);

					TriangleIndex tri;

					tri.a = *((unsigned short *) &buffer[0]);
					tri.b = *((unsigned short *) &buffer[2]);
					tri.c = *((unsigned short *) &buffer[4]);

					if (tri.a>=vertex.size() || tri.b>=vertex.size() || tri.c>=vertex.size())
						cerr << "Error: Face data out of range." << endl;
					else
					{
						triangle.push_back(tri);

						TAB(2);
						DOUT(2) << tri.a << ',' << tri.b << ',' << tri.c << endl;
					}
				}
			}
			break;
		case 0x4130:						// Face Material
			readMaterial(is,subChunkSize-6);
			break;
		default:
			eatChunk(is,subChunkSize-6);
		}

		if (!subChunkID || size<subChunkSize)
			break;

		size -= subChunkSize;
	}

	if (callback)
		callback(vertex,triangle,name);

	tab--;
}
开发者ID:funkjunky,项目名称:Demos-and-Tutorials,代码行数:100,代码来源:read3dsb.cpp


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