本文整理汇总了C++中std::ifstream::eof方法的典型用法代码示例。如果您正苦于以下问题:C++ ifstream::eof方法的具体用法?C++ ifstream::eof怎么用?C++ ifstream::eof使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::ifstream
的用法示例。
在下文中一共展示了ifstream::eof方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getHead
inline void FileParse::getHead(std::ifstream& fin) {
if (fin.eof()) return;
// Create a new head node
HeadNode *node = new HeadNode;
// Look for the heading. Ends with ":", or "{". If "{" is encountered, body = true.
bool body = false;
getHeading(fin, node->heading, body);
// Message
message += (tabs() + "Level " + toStr(level) + ": Heading: [" + node->heading + "]\n");
// Set node as the current head
node->parent = currentHead;
currentHead = node;
// Look for parameters
bool newLine = passSpaces(fin);
// Get the parameters - adds them to the current head node
if (!fin.eof() && !newLine && !body)
body = getParameters(fin);
++level;
if (body && !fin.eof()) getBody(fin);
--level;
// Add this node to the parent node
node->parent->subHeads.push_back(node);
// Return to parent node
currentHead = node->parent;
}
示例2: findInStream
size_t findInStream(std::ifstream &stream, const std::string &sig)
{
const size_t start = stream.tellg();
while(!stream.eof())
{
auto it = sig.begin();
for( size_t s=0 ; it != sig.end() ; it++, s++ )
{
char c = stream.get();
if( sig[s] != c )
break;
}
if( it == sig.end() )
break;
}
size_t pos;
if(stream.eof())
pos = std::string::npos;
else
pos = stream.tellg();
stream.seekg(start);
return pos;
}
示例3: iss
InputData::InputData(std::ifstream& input) {
std::string label;
input >> label >> name_;
// std::cout << label << name_ << "\n";
input >> label >> nirreps_;
// std::cout << label << " " << nirreps_ << "\n";
input >> label >> nmo_;
// std::cout << label << " " << nmo_ << "\n";
input >> label >> nocc_act_alpha_;
// std::cout << label << " " << nocc_act_alpha_ << "\n";
input >> label >> nocc_act_beta_;
// std::cout << label << " " << nocc_act_beta_ << "\n";
input >> label >> nvir_act_alpha_;
// std::cout << label << " " << nvir_act_alpha_ << "\n";
input >> label >> nvir_act_beta_;
// std::cout << label << " " << nvir_act_beta_ << "\n";
input >> label;
// std::cout << label << "\n";
obs_mosym_alpha_.resize(nmo_, 0);
for(obs_mosym::iterator it = obs_mosym_alpha_.begin(); it != obs_mosym_alpha_.end(); ++it) {
input >> *it;
// std::cout << *it << "\n";
}
input >> label;
// std::cout << label << "\n";
obs_mosym_beta_.resize(nmo_, 0);
for(obs_mosym::iterator it = obs_mosym_beta_.begin(); it != obs_mosym_beta_.end(); ++it) {
input >> *it;
// std::cout << *it << "\n";
}
std::string line;
std::getline(input, line);
std::getline(input, line);
do {
line.clear();
std::getline(input, line);
if(line.size() == 0ul)
break;
std::istringstream iss(line);
array2d::value_type data;
iss >> data.first[0] >> data.first[1] >> data.second;
f_.push_back(data);
// std::cout << "(" << data.first[0] << ", " << data.first[1] << ") " << data.second << "\n";
} while(! input.eof());
do {
line.clear();
std::getline(input, line);
if(line.size() == 0ul)
break;
std::istringstream iss(line);
array4d::value_type data;
// Note: Input data is in chemist notation order, but we want physicist notation.
// So we swap index 1 and 2
iss >> data.first[0] >> data.first[2] >> data.first[1] >> data.first[3] >> data.second;
v_ab_.push_back(data);
// std::cout << "(" << data.first[0] << ", " << data.first[1] << ", " << data.first[2]
// << ", " << data.first[3] << ") " << data.second << "\n";
} while(! input.eof());
}
示例4: LoadNextSeq
// Load next chromosome
ref_loc_t RefSeq::LoadNextSeq(std::ifstream &fin) {
char c;
char ch[1000];
std::string s;
fin>>c;
if (fin.eof()) return 0;
_length = 0;
// get name
fin>>_name;
fin.getline(ch, 1000);
// get seq
while (!fin.eof()) {
fin>>c;
if (fin.eof()) break;
fin.unget();
if (c == '>') break;
fin>>s;
if (_length + s.size() >= param.max_dbseq_size) {
if (s.size() > param.append_dbseq_size) {
param.max_dbseq_size += (s.size() + 10);
} else {
param.max_dbseq_size += param.append_dbseq_size;
}
_seq.resize(param.max_dbseq_size);
}
copy(s.begin(), s.end(), _seq.begin() + _length);
_length += s.size();
}
return _length;
}
示例5: loadOFF
bool MeshModel::loadOFF(std::ifstream& infile)
{
std::string temp;
infile >> temp;
unsigned int numVertices,numFaces;
infile >> numVertices >> numFaces >> temp;
if (infile.eof())
return false;
vertices.resize(numVertices);
double z;
for (unsigned int i = 0; i < numVertices; i++) {
if (infile.eof()) return false;
infile >> vertices[i].x >> vertices[i].y >> z;
}
int three;
faces->resize(numFaces);
for (unsigned int i = 0; i < numFaces; i++) {
if (infile.eof()) return false;
infile >> three >> (*faces)[i][0] >> (*faces)[i][1] >> (*faces)[i][2];
}
identityTexCoords();
return updateMeshInfo();
}
示例6: ReadTextImageData
void DTMImage::ReadTextImageData( std::ifstream & ifs )
{
ifs.seekg(0,std::ios::beg);
SkipUntilNum(ifs);
int Dimensions[3];
for ( int i = 0; i < 3; ++i ) ifs >> Dimensions[i];
this->SetDimensions(Dimensions);
SkipUntilNum(ifs);
for ( int i = 0; i < 3; ++i ) ifs >> this->origin[i];
SkipUntilNum(ifs);
for ( int i = 0; i < 3; ++i ) ifs >> this->spacing[i];
SkipUntilNum(ifs);
for ( int i = 0; i < 3; ++i ) ifs >> this->indexIncrement[i];
SkipUntilNum(ifs);
ifs >> this->scalarType;
// We are assuming that the scalar type is double.
// When we template the class we will fix all these things.
this->scalars->resize(this->dimensions[0]*this->dimensions[1]*this->dimensions[2]);
this->scalars->clear();
double tmp = 0;
SkipUntilNum(ifs);
while( !ifs.eof() )
{
ifs >> tmp >> std::skipws;
if ( !ifs.eof() )
this->scalars->push_back(tmp);
}
if ( this->scalars->size() != (std::size_t)this->pointProduct[2] )
std::cerr << "The number of scalars read do not match the dimensions.";
}
示例7:
binary_reader::market_message::market_message( std::ifstream& in )
{
type_=0u;time_=0u;
len_=0u;msg_=NULL;
if(!in.read(reinterpret_cast<char *>(&type_), sizeof(type_))) {
if (in.eof()) return;
cerr<<"Input is incorrect type"<<endl;
return;
}
if(!in.read(reinterpret_cast<char *>(&time_), sizeof(time_))) {
if (in.eof()) return;
cerr<<"Input is incorrect time"<<endl;
return;
}
if(!in.read(reinterpret_cast<char *>(&len_), sizeof(len_))) {
if (in.eof()) return;
cerr<<"Input is incorrect len"<<endl;
return;
}
msg_ = new char[len_+1];
memset(msg_, 0, len_ +1);
if(!in.read(msg_, len_)) {
if (in.eof()) return;
cerr<<"Input is incorrect msg"<<endl;
return;
}
}
示例8: read
virtual bool read(std::ifstream& in, int n, bool binary)
{
resize(n);
if (binary)
{
in.read((char*)data, n * sizeof(T));
if (in.eof() || in.bad())
{
resize(0);
return false;
}
}
else
{
int i = 0;
std::string line;
while(i < dataSize && !in.eof() && !in.bad())
{
std::getline(in, line);
std::istringstream ln(line);
while (i < n && ln >> data[i])
++i;
}
if (i < n)
{
resize(0);
return false;
}
}
return true;
}
示例9: load_ref
void load_ref( std::ifstream &is ) {
size_t num_ref;
is >> num_ref;
m_ref_pvecs.resize( num_ref );
m_ref_aux.resize( num_ref );
for( size_t i = 0; i < m_ref_pvecs.size(); ++i ) {
size_t len;
is >> len;
while( isspace( is.get() ) && !is.eof() ) {}
is.unget();
if( is.eof() ) {
throw std::runtime_error( "unexpected end of file" );
}
m_ref_pvecs[i].resize(len);
is.read( (char*)&m_ref_pvecs[i][0], len * sizeof(int) );
m_ref_aux[i].resize(len);
is.read( (char*)&m_ref_aux[i][0], len * sizeof(unsigned int) );
// std::cout << "ref: " << i << " " << m_ref_pvecs[i].size() << "\n";
}
}
示例10: readCharInfo
/**
* Parse the stream for the characterization file information.
*
* @param file The stream to parse.
* @param wksp The table workspace to fill in.
*/
void PDLoadCharacterizations::readCharInfo(std::ifstream &file, ITableWorkspace_sptr &wksp)
{
// end early if already at the end of the file
if (file.eof()) return;
// parse the file
for (std::string line = Strings::getLine(file); !file.eof(); line = Strings::getLine(file))
{
line = Strings::strip(line);
// skip empty lines and "comments"
if (line.empty()) continue;
if (line.substr(0,1) == "#") continue;
// parse the line
std::vector<std::string> splitted;
boost::split(splitted, line, boost::is_any_of("\t "), boost::token_compress_on);
while (splitted.size() < 10)
splitted.push_back(ZERO); // extra values default to zero
// add the row
API::TableRow row = wksp->appendRow();
row << boost::lexical_cast<double>(splitted[0]); // frequency
row << boost::lexical_cast<double>(splitted[1]); // wavelength
row << boost::lexical_cast<int32_t>(splitted[2]); // bank
row << boost::lexical_cast<int32_t>(splitted[3]); // vanadium
row << boost::lexical_cast<int32_t>(splitted[4]); // container
row << boost::lexical_cast<int32_t>(splitted[5]); // empty
row << splitted[6]; // d_min
row << splitted[7]; // d_max
row << boost::lexical_cast<double>(splitted[8]); // tof_min
row << boost::lexical_cast<double>(splitted[9]); // tof_max
}
}
示例11: EXCEPTION
void UNV2417::Read(std::ifstream& in_stream, TDataSet& theDataSet)
{
if(!in_stream.good())
EXCEPTION(runtime_error,"ERROR: Input file not good.");
std::string olds, news;
while(true){
in_stream >> olds >> news;
/*
* a "-1" followed by a number means the beginning of a dataset
* stop combing at the end of the file
*/
while( ((olds != "-1") || (news == "-1") ) && !in_stream.eof() ){
olds = news;
in_stream >> news;
}
if(in_stream.eof())
return;
for (int i = 0; i < NBGROUP; i++) {
if (news == _group_labels[i]) {
ReadGroup(news, in_stream, theDataSet);
}
}
}
}
示例12: insert_signals
int insert_signals( T& signal,
char * signal_name,
char * wu_name,
sqlint8_t sah_result_id,
std::ifstream& result_file,
receiver_config& receiver_cfg,
int appid,
int max_signals_allowed,
list<long>& qpixlist) {
int signal_count=0, signal_inserted_count=0, retval=0, qpix;
sqlint8_t signal_id=0;
result_file.clear();
result_file.seekg(0);
while (!result_file.eof()) {
result_file >> signal;
if (!result_file.eof()) {
signal_count++;
if (max_signals_allowed == 0 || signal_count <= max_signals_allowed) {
if (!(signal.rfi_found = check_values(signal, sah_result_id, wu_name))) {
// preprocess only if we have good values
retval = pre_process(signal, receiver_cfg);
qpixlist.push_back(npix2qpix((long long)signal.q_pix));
}
signal.result_id = sah_result_id;
if (appid == 2) signal.reserved = 1; // temporary for enhanced rollout
signal_id = signal.insert();
if (signal_id) {
log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG,
"[%s] Inserted %s %"INT8_FMT" for sah result %"INT8_FMT"\n",
wu_name, signal_name, INT8_PRINT_CAST(signal_id), INT8_PRINT_CAST(sah_result_id)
);
signal_inserted_count++;
} else {
log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,
"[%s] Could not insert %s for sah result %"INT8_FMT". SQLCODE is %d. q_pix is %"INT8_FMT" ra is %lf decl is %lf .\n",
wu_name, signal_name, sah_result_id, sql_last_error_code(), signal.q_pix, signal.ra, signal.decl
);
#if 0
log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,
"[%s] Could not insert %s for sah result %ld. SQLCODE is %d. SQLMSG is %s q_pix is %"INT8_FMT".\n",
wu_name, signal_name, sah_result_id, sql_last_error_code(), sql_error_message(), signal.q_pix
);
#endif
return -1;
}
}
}
}
log_messages.printf(SCHED_MSG_LOG::MSG_NORMAL,
"[%s] Inserted %d out of %d %s(s) for sah result %"INT8_FMT" \n",
wu_name, signal_inserted_count, signal_count, signal_name, INT8_PRINT_CAST(sah_result_id)
);
}
示例13: ParseFoodItem
bool ParseFoodItem(std::ifstream & infile, FoodItem & item)
{
if (true == infile.eof())
{
return false;
}
const int MAX_TOKEN = 256;
std::string line;
std::string tokenBuf(MAX_TOKEN, '\0');
const char * delim = ",\n";
do
{
float calories = 0;
// read line
std::getline(infile, line);
// grab first token
char * token = nullptr;
char * nextToken = nullptr;
token = strtok_s(&line[0], delim, &nextToken);
std::string tokenStr(token);
//trim_str(tokenStr);
String nameToken(ConvertStringToWString(token)); // read name, 1st token
// next token plz
token = strtok_s(nullptr, delim, &nextToken);
if (token == nullptr)
{
return false;
}
// read calories, 2nd token
calories = (float)atof(token);
if (calories <= 0)
{
return false;
}
// read description
std::string desc;
std::getline(infile, desc);
String measurements(ConvertStringToWString(desc));
item = FoodItem(nameToken, measurements, calories);
return true;
}
while (false == infile.eof());
return false;
}
示例14: ReadScalars
void ReadScalars(std::ifstream &ifs, size_t pos, std::vector<T> &Scalars)
{
ifs.seekg(pos,std::ios::beg);
Scalars.clear();
while( !ifs.eof() )
{
T tmp;
ifs.read(reinterpret_cast<char *>(&tmp), sizeof(T));
if ( !ifs.eof() )
Scalars.push_back(tmp);
}
}
示例15: readData
// Read the data
//-------------------------------------------------------------------------------------------------
bool PPM::readData(std::ifstream &inFile)
{
// Read data into r, g and b vectors
// Note: if << is used data that looks like a white space will be skipped
char c;
int length = m_width * m_height;
for(int i = 0; i < length; ++i)
{
// Red
inFile.read(&c, 1); // read a byte
// Check for eof
if(inFile.eof())
{
std::cerr << "Error in readData: unexpected end of file" << std::endl;
return false;
}
// Set value
(*m_pR)[i] = (unsigned char)c;
// Green
inFile.read(&c, 1); // read a byte
// Check for eof
if(inFile.eof())
{
std::cerr << "Error in readData: unexpected end of file" << std::endl;
return false;
}
// Set value
(*m_pG)[i] = (unsigned char)c;
// Blue
inFile.read(&c, 1); // read a byte
// Check for eof
if(inFile.eof())
{
std::cerr << "Error in readData: unexpected end of file" << std::endl;
return false;
}
// Set value
(*m_pB)[i] = (unsigned char)c;
}
// Check the data is valid
if(!checkData())
{
std::cerr << "Error in readData: invalid data" << std::cout;
return false;
}
return true;
}