本文整理汇总了C++中std::ifstream::getline方法的典型用法代码示例。如果您正苦于以下问题:C++ ifstream::getline方法的具体用法?C++ ifstream::getline怎么用?C++ ifstream::getline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::ifstream
的用法示例。
在下文中一共展示了ifstream::getline方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readInitialCoordinates
void GamessukOut::readInitialCoordinates(std::ifstream& ifs)
{
// string to mark end of the coordinates
char coordEnd[86] = " "
"********************************************************"
"********************";
double x = 0.0, y = 0.0, z = 0.0;
// skip five lines
ifs.getline(buffer, BUFF_SIZE) && ifs.getline(buffer, BUFF_SIZE) &&
ifs.getline(buffer, BUFF_SIZE) && ifs.getline(buffer, BUFF_SIZE) &&
ifs.getline(buffer, BUFF_SIZE);
while (strstr(buffer, coordEnd) == nullptr) {
// std::cout << "COORD line" << buffer << std::endl;
// ifs.getline(buffer, BUFF_SIZE);
tokenize(tokens, buffer, " \t\n");
if (tokens.size() == 8) {
// std::cout << "Coord line" << buffer << std::endl;
gukBasis.atomLabels.push_back(tokens.at(1));
from_string<double>(x, tokens.at(3), std::dec);
from_string<double>(y, tokens.at(4), std::dec);
from_string<double>(z, tokens.at(5), std::dec);
gukBasis.coordinates.push_back(
Eigen::Vector3d(x, y, z)); // Want coordinates in Bohr
}
ifs.getline(buffer, BUFF_SIZE);
}
}
示例2: open
void GlowNodeGroup::open(std::ifstream& fp)
{
int type = 0;
int end_found = 0;
char dummy[40];
for (;;) {
if (!fp.good()) {
fp.clear();
fp.getline(dummy, sizeof(dummy));
printf("** Read error GlowNodeGroup: \"%d %s\"\n", type, dummy);
}
fp >> type;
switch (type) {
case glow_eSave_NodeGroup:
break;
case glow_eSave_NodeGroup_nodeclass_part:
GlowNodeClass::open(fp);
break;
case glow_eSave_End:
end_found = 1;
break;
default:
std::cout << "GrowGroup:open syntax error\n";
fp.getline(dummy, sizeof(dummy));
}
if (end_found)
break;
}
}
示例3: ReadPROP
// ================== (2) PC variables ==================== //
void DetectorGeo::ReadPROP(std::ifstream &file)
{
char ReadIn[280];
// skip to and over the + sign
do
{
file.getline(ReadIn,280,'\n');
} while(ReadIn[0] != '+');
// Radius, thickness of mylar foil in PC
file>>rp_myl>>tp_myl;
// std::cout << "Mylar radius, thickness " << rp_myl << " "<<tp_myl <<"\n";
//Total number of foils in prop. chamber
file >> npfoils;
// std::cout<<"npfoils " << npfoils <<std::endl;
//position the Mylar foils defining PC wire planes
for(int ipfoil=0; ipfoil<npfoils; ipfoil++)
{
file >> zpfoil[ipfoil];
// std::cout << ipfoil << " " << zpfoil[ipfoil] << "\n";
}
// skip to and over the + sign
do
{
file.getline(ReadIn,280,'\n');
} while(ReadIn[0] != '+');
// Radius, length of PC sense wires, spacing between wires in PC and,
// Number of physical wires/PC plane
file >> pw_rad >> pw_len >> pw_space >> npwires_physical;
// std::cout << "pw_rad, pw_len, pw_space, npwires_physical \n";
// std::cout << pw_rad << " " << pw_len << " " << pw_space << " "
// << npwires_physical << "\n";
//Total number of prop planes and Thickness of gas volume
file >>npplanes>>tp_plane;
// std::cout<<"npplanes, tp_plane " << npplanes << tp_plane<<std::endl;
// skip to and over the + sign
do
{
file.getline(ReadIn,280,'\n');
} while(ReadIn[0] != '+');
// plane positions in PC
int plane;
for(int ipplane=0; ipplane<npplanes; ipplane++)
{
file >> plane >> zpplane[ipplane] >> pshift[ipplane] >> prot[ipplane]
>> npwires[ipplane];
// std::cout << ipplane << " " <<zpplane[ipplane]<< " " <<pshift[ipplane]
// << " " <<prot[ipplane]<< " " <<npwires[ipplane]<< "\n";
}
}
示例4: MatrixInput
MMFormatInput::MMFormatInput(std::ifstream &in, std::vector<uint32_t> &permIn) : MatrixInput(), in(in), curRow(0), curIndex(-1), already_read(false), perm(permIn) {
//read header only
char buf[500];
isBinary = false;
in.getline(buf, 500);
if ( strstr(buf, "pattern") != NULL ) {
isBinary = true; }
do {
in.getline(buf, 500);
if (in.gcount() >=500){
cerr << "FAILED FORMAT" << endl;
exit(1);
}
} while (buf[0] == '%');
uint32_t nr, nc, nnz;
sscanf( buf , "%d %d %d", &nr, &nc, &nnz);
this->nnz = nnz;
this->numRows = nr;
this->numCols = nc;
if (perm.size() == 0) {
perm.resize( max(numRows, numCols) );
for (int i=0; i<perm.size(); i++) {
perm[i] = i;
}
}
}
示例5: open
void GlowText::open(std::ifstream& fp)
{
int type = 0;
int end_found = 0;
char dummy[40];
char tmp_text[500];
int tmp;
for (;;) {
if (!fp.good()) {
fp.clear();
fp.getline(dummy, sizeof(dummy));
printf("** Read error GlowText: \"%d %s\"\n", type, dummy);
}
fp >> type;
switch (type) {
case glow_eSave_Text:
break;
case glow_eSave_Text_text_size:
fp >> text_size;
break;
case glow_eSave_Text_draw_type:
fp >> tmp;
draw_type = (glow_eDrawType)tmp;
break;
case glow_eSave_Text_color_drawtype:
fp >> tmp;
color_drawtype = (glow_eDrawType)tmp;
break;
case glow_eSave_Text_text:
fp.get();
fp.getline(tmp_text, sizeof(tmp_text));
free(text);
text = (char*)malloc(strlen(tmp_text) + 1);
strcpy(text, tmp_text);
break;
case glow_eSave_Text_p:
p.open(fp);
break;
case glow_eSave_End:
end_found = 1;
break;
default:
std::cout << "GlowText:open syntax error\n";
fp.getline(dummy, sizeof(dummy));
}
if (end_found)
break;
}
}
示例6: errStr
void Tpetra::Utils::readHBHeader(std::ifstream &fin, Teuchos::ArrayRCP<char> &Title, Teuchos::ArrayRCP<char> &Key, Teuchos::ArrayRCP<char> &Type,
int &Nrow, int &Ncol, int &Nnzero, int &Nrhs,
Teuchos::ArrayRCP<char> &Ptrfmt, Teuchos::ArrayRCP<char> &Indfmt, Teuchos::ArrayRCP<char> &Valfmt, Teuchos::ArrayRCP<char> &Rhsfmt,
int &Ptrcrd, int &Indcrd, int &Valcrd, int &Rhscrd, Teuchos::ArrayRCP<char> &Rhstype) {
int Totcrd, Neltvl, Nrhsix;
const int MAXLINE = 81;
char line[MAXLINE];
//
Title.resize(72 + 1); std::fill(Title.begin(), Title.end(), '\0');
Key.resize(8 + 1); std::fill(Key.begin(), Key.end(), '\0');
Type.resize(3 + 1); std::fill(Type.begin(), Type.end(), '\0');
Ptrfmt.resize(16 + 1); std::fill(Ptrfmt.begin(), Ptrfmt.end(), '\0');
Indfmt.resize(16 + 1); std::fill(Indfmt.begin(), Indfmt.end(), '\0');
Valfmt.resize(20 + 1); std::fill(Valfmt.begin(), Valfmt.end(), '\0');
Rhsfmt.resize(20 + 1); std::fill(Rhsfmt.begin(), Rhsfmt.end(), '\0');
//
const std::string errStr("Tpetra::Utils::readHBHeader(): Improperly formatted H/B file: ");
/* First line: (A72,A8) */
fin.getline(line,MAXLINE);
TEUCHOS_TEST_FOR_EXCEPTION( std::sscanf(line,"%*s") < 0, std::runtime_error, errStr << "error buffering line.");
(void)std::sscanf(line, "%72c%8[^\n]", Title.getRawPtr(), Key.getRawPtr());
/* Second line: (5I14) or (4I14) */
fin.getline(line,MAXLINE);
TEUCHOS_TEST_FOR_EXCEPTION(std::sscanf(line,"%*s") < 0, std::runtime_error, errStr << "error buffering line.");
if ( std::sscanf(line,"%14d%14d%14d%14d%14d",&Totcrd,&Ptrcrd,&Indcrd,&Valcrd,&Rhscrd) != 5 ) {
Rhscrd = 0;
TEUCHOS_TEST_FOR_EXCEPTION(std::sscanf(line,"%14d%14d%14d%14d",&Totcrd,&Ptrcrd,&Indcrd,&Valcrd) != 4, std::runtime_error, errStr << "error reading pointers (line 2)");
}
/* Third line: (A3, 11X, 4I14) */
fin.getline(line,MAXLINE);
TEUCHOS_TEST_FOR_EXCEPTION(std::sscanf(line,"%*s") < 0, std::runtime_error, errStr << "error buffering line.");
TEUCHOS_TEST_FOR_EXCEPTION(std::sscanf(line, "%3c%14i%14i%14i%14i", Type.getRawPtr(),&Nrow,&Ncol,&Nnzero,&Neltvl) != 5 , std::runtime_error, errStr << "error reading matrix meta-data (line 3)");
std::transform(Type.begin(), Type.end(), Type.begin(), static_cast < int(*)(int) > (std::toupper));
/* Fourth line: */
fin.getline(line,MAXLINE);
TEUCHOS_TEST_FOR_EXCEPTION(std::sscanf(line,"%*s") < 0, std::runtime_error, errStr << "error buffering line.");
if (Rhscrd != 0) {
TEUCHOS_TEST_FOR_EXCEPTION(std::sscanf(line,"%16c%16c%20c%20c",Ptrfmt.getRawPtr(),Indfmt.getRawPtr(),Valfmt.getRawPtr(),Rhsfmt.getRawPtr()) != 4, std::runtime_error, errStr << "error reading formats (line 4)");
}
else {
TEUCHOS_TEST_FOR_EXCEPTION(std::sscanf(line,"%16c%16c%20c",Ptrfmt.getRawPtr(),Indfmt.getRawPtr(),Valfmt.getRawPtr()) != 3, std::runtime_error, errStr << "error reading formats (line 4)");
}
/* (Optional) Fifth line: */
if (Rhscrd != 0 ) {
Rhstype.resize(3 + 1,'\0');
fin.getline(line,MAXLINE);
TEUCHOS_TEST_FOR_EXCEPTION(std::sscanf(line,"%*s") < 0, std::runtime_error, errStr << "error buffering line.");
TEUCHOS_TEST_FOR_EXCEPTION(std::sscanf(line,"%3c%14d%14d", Rhstype.getRawPtr(), &Nrhs, &Nrhsix) != 3, std::runtime_error, errStr << "error reading right-hand-side meta-data (line 5)");
}
}
示例7: load
int UserList::load(std::ifstream& fp)
{
int type;
int end_found = 0;
char dummy[40];
for (;;) {
fp >> type;
switch (type) {
case user_eData_User:
break;
case user_eData_UserName:
fp.get();
fp.getline(name, sizeof(name));
break;
case user_eData_UserPassword:
fp.get();
fp.getline(password, sizeof(password));
break;
case user_eData_UserPrivilege:
fp >> priv;
priv = idecrypt(priv);
break;
case user_eData_UserId:
fp >> id;
break;
case user_eData_UserFullName:
fp.get();
fp.getline(fullname, sizeof(fullname));
break;
case user_eData_UserDescription:
fp.get();
fp.getline(description, sizeof(description));
break;
case user_eData_UserEmail:
fp.get();
fp.getline(email, sizeof(email));
break;
case user_eData_UserPhone:
fp.get();
fp.getline(phone, sizeof(phone));
break;
case user_eData_UserSms:
fp.get();
fp.getline(sms, sizeof(sms));
break;
case user_eData_End:
end_found = 1;
break;
default:
std::cout << "User:open syntax error\n";
fp.getline(dummy, sizeof(dummy));
}
if (end_found)
break;
}
return 1;
}
示例8: _readDocumentHeader
void _readDocumentHeader() {
char line[65536];
if( !_in.good() || _in.eof() )
return;
// DOCNO=
_in.getline( _docno, sizeof _docno-1 );
// DOCURL=
_in.getline( line, sizeof line-1 );
// LINKS=
_in.getline( line, sizeof line-1 );
_count = atoi( line+6 );
}
示例9: SkipHeaderLines
/**
* This helper method just moves forward the two file pointers to skip some header lines.
* @param numLinesToSkip The number of header lines to skip
*/
void SkipHeaderLines(unsigned numLinesToSkip)
{
if (!mCalledCollectively || PetscTools::AmMaster())
{
for (unsigned line_number=0; line_number<numLinesToSkip; line_number++)
{
char buffer[1024];
mpFile1->getline(buffer, 1024);
mpFile2->getline(buffer, 1024);
TS_ASSERT(!mpFile1->fail()); // Here we assume there are at least "ignoreFirstFewLines" lines...
TS_ASSERT(!mpFile2->fail()); // ...and that they are lines of no more than 1024 characters
mLineNum++;
}
}
}
示例10: open
void GrowSlider::open(std::ifstream& fp)
{
int type = 0;
int end_found = 0;
char dummy[40];
int tmp;
for (;;) {
if (!fp.good()) {
fp.clear();
fp.getline(dummy, sizeof(dummy));
printf("** Read error GrowSlider: \"%d %s\"\n", type, dummy);
}
fp >> type;
switch (type) {
case glow_eSave_GrowSlider:
break;
case glow_eSave_GrowSlider_direction:
fp >> tmp;
direction = (glow_eDirection)tmp;
break;
case glow_eSave_GrowSlider_max_value:
fp >> max_value;
break;
case glow_eSave_GrowSlider_min_value:
fp >> min_value;
break;
case glow_eSave_GrowSlider_max_pos:
fp >> max_pos;
break;
case glow_eSave_GrowSlider_min_pos:
fp >> min_pos;
break;
case glow_eSave_GrowSlider_grownode_part:
GrowNode::open(fp);
break;
case glow_eSave_End:
end_found = 1;
break;
default:
std::cout << "GrowSlider:open syntax error\n";
fp.getline(dummy, sizeof(dummy));
}
if (end_found)
break;
}
}
示例11:
void ResourceManager::getI2NBlock(std::ifstream &file,
Resource::Mapping &mapping,
bool files,
const std::string &dir,
const std::string &ext)
{
uint id;
const int bufferSize = 80;
char buffer[bufferSize];
while (!file.eof() && file.peek() != '#')
{
file >> id;
if (!(file.peek() == '.'))
return;
file.ignore(2, ' ');
file.getline(buffer, bufferSize);
fixLineEnd(buffer);
if (files)
{
std::string path = dir + '/' + std::string(buffer) + ext;
Normalize(path);
mapping[id] = path;
}
else
{
mapping[id] = std::string(buffer);
}
}
}
示例12: 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;
}
示例13: ReadWorldTagData
void ReadWorldTagData( std::ifstream &inStream, UString &tag, UString &data )
{
char temp[4096];
tag = "o---o";
data = "o---o";
while( !inStream.eof() && !inStream.fail() )
{
inStream.getline( temp, 4096 );
UString sLine( temp );
sLine = sLine.removeComment().stripWhiteSpace();
if( !sLine.empty() )
{
if( sLine != "o---o" )
{
if( sLine.sectionCount( "=" ) == 1 )
{
tag = sLine.section( "=", 0, 0 ).stripWhiteSpace();
data = sLine.section( "=", 1 ).stripWhiteSpace();
break;
}
}
else
break;
}
}
}
示例14: loadFrom
int CSheet::loadFrom(std::ifstream& in)
{
int lines = 0;
while(!in.eof())
{
//读取其中一行
char line[256] = {0};
in.getline(line, 255);
CString s = /*(CString)*/static_cast<CString>(line);
//空白行则跳过
if (s.IsEmpty())
continue;
//#为注释标记,跳过
if (s[0]=='#')
continue;
//如果读到字母则跳过
if (s[0]>='a' && s[0]<='z')
continue;
CStringArray* pRow = new CStringArray();
int i = 0;
CString token = s.Tokenize(_T(",\t"), i);
while (token!=_T(""))
{
pRow->Add(token);
token = s.Tokenize(_T(",\t"), i);
}
m_rows.Add(pRow);
lines++;
}
return lines;
}
示例15:
void l1menu::TriggerMenu::loadMenuInOldFormat( std::ifstream& file )
{
const size_t bufferSize=200;
char buffer[bufferSize];
while( file.good() )
{
try
{
// Get one line at a time
file.getline( buffer, bufferSize );
// split the line by whitespace into columns
std::vector<std::string> tableColumns=l1menu::tools::splitByWhitespace( buffer );
if( tableColumns.size()==1 && tableColumns[0].empty() ) continue; // Allow blank lines without giving a warning
if( tableColumns.size()!=12 ) throw std::runtime_error( "The line does not have the correct number of columns" );
addTriggerFromOldFormat( tableColumns );
} // end of try block
catch( std::runtime_error& exception )
{
std::cout << "Some error occured while processing the line \"" << buffer << "\":" << exception.what() << std::endl;
}
}
}