本文整理汇总了C++中ifstream::eatwhite方法的典型用法代码示例。如果您正苦于以下问题:C++ ifstream::eatwhite方法的具体用法?C++ ifstream::eatwhite怎么用?C++ ifstream::eatwhite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ifstream
的用法示例。
在下文中一共展示了ifstream::eatwhite方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getField
BOOL static getField(ifstream& fin, CString& marker, CString& contents)
{
static BOOL bNextLineIsBlank=FALSE;
if(bNextLineIsBlank)
{
bNextLineIsBlank=FALSE;
marker = "BLANKLINE";
contents ="";
return TRUE;
}
ASSERTX(fin.is_open());
const int kBuffSize = 5000; // CURRENTLY MAX FIELD SIZE TOO!
CString sField;
LPTSTR buff = sField.GetBuffer(kBuffSize+2);
LPTSTR start_buff = buff;
fin.eatwhite();
char* b = buff;
BOOL bFoundBlank = FALSE;
do
{
fin.getline(b, kBuffSize - (b-buff), '\n');
b += fin.gcount();
if(fin.gcount())
{
*(b-1) = '\n'; // put a carriage return in place of the null terminator
*b = '\0'; // null terminate in case the next getline fails
}
while(fin.peek() == '\n') // keep swallowing blank lines until we see what's at the end of them
{
fin.get(); // swallow the \n;
if(fin.peek() == '\\') // if the blanks are followed by a record, then this constitutes a true blank line
{
bFoundBlank=TRUE;
break;
}
}
} while (!bFoundBlank && fin.good() && fin.gcount() && fin.peek() != '\\');
bNextLineIsBlank = bFoundBlank; // will be used on the next call
if( (kBuffSize-1) <= (b-buff)) // to long (and thus fin.gcount() == 0)
{
CString s;
s.Format("The interlinear file appears to have a line which is longer than the maximum of %d characters which csCleanITX can handle.\n",
kBuffSize);
throw(s);
}
if(!buff[0]) // end of file
{ sField.ReleaseBuffer(-1);
return FALSE;
}
// eat white space before the SFM Code (will always be there after a \dis)
while(*buff && _ismbcspace(*buff))
{
*buff='~'; // a hack so that iSpaceLoc, below, isn't set to the space between the "\dis" and marker
++buff;
}
int iSpaceLoc ;
// figure out where the marker ends and field contents begin
iSpaceLoc = sField.FindOneOf(" \t\n");
if(iSpaceLoc <= 1)// [0] should be the slash, [1] at least one char
{ sField.ReleaseBuffer(-1);
return FALSE;
}
start_buff[iSpaceLoc] = '\0';
marker = buff + 1; // +1 to skip the slash
marker.TrimRight();
contents = start_buff + iSpaceLoc+1;
contents.TrimLeft();
contents.TrimRight();
sField.ReleaseBuffer(-1);
return TRUE;
}