本文整理汇总了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
}
}
示例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) {
}
}
示例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;
}
示例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();
}
示例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;
}
示例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
}
示例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_));
}
示例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());
}
}
示例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();
}
};
示例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));
}
示例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;
}
示例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;
}
示例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);
//}
//.........这里部分代码省略.........
示例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();
}
示例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--;
}