本文整理汇总了C++中stringstream::eof方法的典型用法代码示例。如果您正苦于以下问题:C++ stringstream::eof方法的具体用法?C++ stringstream::eof怎么用?C++ stringstream::eof使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stringstream
的用法示例。
在下文中一共展示了stringstream::eof方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readCha
int readCha(string &res, stringstream &strIn) {
res = "";
char ch;
while (~(ch = strIn.get()) &&
(ch == ' ' || ch == '\n' || ch == '\t')) {
;
}
if (strIn.eof()) return END;
if (ch == '\'') {
res += ch;
strIn >> ch;
if (strIn.eof()) {
strIn.putback(ch);
return ERR;
}
if (ch == '\\') {
res += ch;
if ((ch = strIn.get()) == -1) return ERR;
res += ch;
if ((ch = strIn.get()) == -1 || ch != '\'') {
return ERR;
}
res += ch;
} else {
res += ch;
// cout << ch << endl;
if ((ch = strIn.get()) == -1 || ch != '\'') {
return ERR;
}
res += ch;
}
} else {
示例2: readInt
//checked
int readInt(string &fres, stringstream &strIn, bool can = true) {
if (can)
fres = "";
string res = "";
char ch;
while (~(ch = strIn.get()) &&
(ch == ' ' || ch == '\n' || ch == '\t')) {
;
}
if (strIn.eof()) return END;
if (ch == '+' || ch == '-' || (ch >= '0' && ch <= '9')) {
res += ch, fres += ch;
} else {
strIn.putback(ch);
return ERR;
}
while (~(ch = strIn.get()) &&
(ch >= '0' && ch <= '9')) {
res += ch, fres += ch;
}
int st = strIn.eof();
if (st) {
if (isdigit(res[0]) || (int)res.size() > 1)
return OKAY;
else return ERR;
}
strIn.putback(ch);
if ((int)res.size() == 1 && !isdigit(res[0])) {
strIn.putback(res[0]);
}
return isdigit(res[0]) || (int)res.size() > 1 ? OKAY : ERR;
}
示例3: GetColumn
int TablePaser::GetColumn(stringstream& ss_str, std::basic_istream<char>& in_put, string& column)
{
column = "";
if (ss_str.eof())
return -1;
char cur_char[2];
cur_char[1] = 0;
char separator = ' ';
if (ss_str.get(cur_char[0]).eof())
return 1;
if (cur_char[0] == ' ')
return 1;
else if (cur_char[0] == '"')
separator = '"';
else
column += string(cur_char);
while (1)
{
if (ss_str.eof())
{
if (separator == '"')
{
if (in_put.eof())
return 0;
column += string("\n\0");
ss_str.clear();
in_put.getline(LineData, LINE_DATA_MAX);
ss_str << LineData;
}
else
return 0;
}
ss_str.getline(LineData, 4096, separator);
column += LineData;
//column.append(LineData);
if (ss_str.eof())
continue;
if (separator == ' ')
return 1;
else if (separator == '"')
{
if (ss_str.eof())
return 0;
ss_str.get(cur_char[0]);
if (ss_str.eof())
return 1;
else if (cur_char[0] == ' ')
return 1;
else if (cur_char[0] != separator)
separator = ' ';
//column.push_back(cur_char);
column += string(cur_char);
}
}
return -1;
}
示例4: writeMessageStream
void Logger::writeMessageStream(const int level, const string &scope, stringstream &stream) {
std::string line;
while(!stream.eof()) {
getline(stream, line);
writeMessage(level, scope, line);
}
}
示例5: get_nodeid
// function for reading the nodeid from the stringstream. While it reads the
// INTEGER it tests 3 various errors that can arrive from the user
// I set an arbitrary return of -1 for an error occurrence so my function calls
// know if it failed, if not it returns the desired input
int get_nodeid (stringstream &ss, int lowerbound, int upperbound){
int i;
ss >> i;
// check for invalid number my making sure it was read, and also making sure
// if the stored type into the variable matches and to see whether that value
// was not actually written as a double and if a character follows the int
if ((ss.fail() && !(ss.eof())) || ss.peek() == '.'){
if (ss.peek() != ' ' ){
cout << "Error: argument is not a number" <<endl;
return -1;
}
}
// checks the upper and lower bounds on the integer while making sure the
// integer was for sure read and meets the integer type
else if ((i < lowerbound || i > upperbound) && !ss.fail()) {
cout << "Error: value " << i << " is out of permitted range " << lowerbound << "-" << upperbound << endl;
return -1;
}
// this check tells us if an input was read
else if (ss.fail())
{
cout << "Error: missing argument" << endl;
return -1;
}
// if no error raises, return the desired input
return i;
}
示例6: get_l
void get_l(stringstream& os, string& s, char del) {
char t;
while(!os.eof()) {
os >> t;
if(t==del) return;
s += t;
}
}
示例7: catch
bool
parsePoint(stringstream &ss, string &analyst, double &value)
{
try { ss >> analyst; } catch (...) { return false; }
if (ss.eof()) return false;
try { ss >> value; } catch (...) { return false; }
return true;
}
示例8: Parse
void CIF::Parse(stringstream &in)
{
bool vv=false;//very verbose ?
char lastc=' ';
string block="";// Current block data
while(!in.eof())
{
stringstream mess;
mess<<"CIF: Parsing:"<<in.tellg();
(*fpObjCrystInformUser)(mess.str());
while(!isgraph(in.peek()) && !in.eof()) in.get(lastc);
if(in.eof()) break;
if(vv) cout<<endl;
if(in.peek()=='#')
{//Comment
string tmp;
getline(in,tmp);
if(block=="") mvComment.push_back(tmp);
else mvData[block].mvComment.push_back(tmp);
lastc='\r';
if(vv)cout<<"Comment:"<<tmp<<endl;
continue;
}
if(in.peek()=='_')
{//Tag
string tag,value;
in>>tag;
// Convert all dots to underscores to cover much of DDL2 with this DDL1 parser.
for (string::size_type pos = tag.find('.'); pos != string::npos; pos = tag.find('.', ++ pos))
tag.replace(pos, 1, 1, '_');
value=CIFReadValue(in,lastc);
if(value==string("?")) continue;//useless
mvData[block].mvItem[ci_string(tag.c_str())]=value;
if(vv)cout<<"New Tag:"<<tag<<" ("<<value.size()<<"):"<<value<<endl;
continue;
}
if((in.peek()=='d') || (in.peek()=='D'))
{// Data
string tmp;
in>>tmp;
block=tmp.substr(5);
if(vv) cout<<endl<<endl<<"NEW BLOCK DATA: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ->"<<block<<endl<<endl<<endl;
mvData[block]=CIFData();
continue;
}
示例9: FindFileNameInCommand
void FindFileNameInCommand(stringstream &ss, string &fname)
{
while(!ss.eof())
{
ss>>fname;
if( !(fname.find("-")!=string::npos || fname.find("--")!=string::npos) )
{
return;
}
}
}
示例10: solveTheProblem
/************************************************************************
* solveTheProblem *
* Assumes the equations and variables have already been entered *
* solves the problem, writing the solution in TEMP_FILE, *
* including the tags and problem statements if the problem was *
* not completely solved. *
* Then it opens the file for reading, and returns the first line *
* [does not close file] *
************************************************************************/
const char* solveTheProblem() {
int k;
if (isFirst) throw string("solveTheProblem called before initialization");
try {
// reset the buffer to be empty
resultBuffer.str(string());
if(resultBuffer.good()) {
numsols->assign(canonvars->size(),HUGE_VAL);
if (solveeqs(resultBuffer)) {
// should we do checking of solution here?
bool discrep = false;
for (k = 0; k < canoneqf->size(); k++) {
if (checksol((*canoneqf)[k],numsols,RELERR) > 1) {
if (!discrep) {
resultBuffer << "<DISCREPANCIES>" << endl;
discrep = true;
}
resultBuffer << (*canoneqf)[k]->getInfix() << endl;
}
} // loop over equations to check
dimchkeqf(resultBuffer);
// end of "should we do checking of solution here?"
}
}
else throw string("unable to create solution buffer");
}
catch (string message) { throw message; }
catch (...) { throw string("solveTheProblem went boom!!"); }
// this would be a good place to insert checksol ? or after returning
// solution, in solveMoreOfTheProblem ?
try {
resultBuffer.clear();
resultBuffer.seekg(0);
int tk;
try { tk = resultBuffer.eof(); }
catch (...) { throw string("eof?!?"); }
if (! tk) {
string t;
try { t = getaline(resultBuffer); }
catch (...) { throw string("getaline fails???"); }
try { sprintf(lzbfr, "%s", t.c_str()); }
catch(...) { throw string("copy is wrong??"); }
return lzbfr;
}
else return error[4];
}
catch (string message) { throw message; }
catch (...) { throw string("Read went bad!!"); }
return error[3];
}
示例11: main
int main()
{
#ifndef ONLINE_JUDGE
freopen("in_2289.txt","r",stdin);
#endif
while(scanf("%d%d",&n,&m)&&n)
{
memset(mat,false,sizeof(mat));
for(int i=0;i<n;++i)
{
scanf("%s",&buf);
gets(buf);
str.assign(buf);
ss.clear();
ss<<str;
int g;
while(1)
{
ss>>g;
mat[i][g]=true;
if(ss.eof())
{
break;
}
}
}
l=1;
r=n;
while(l<=r)
{
mid=(l+r)>>1;
if(Check())
{
r=mid-1;
}
else
{
l=mid+1;
}
}
printf("%d\n",l);
}
return 0;
}
示例12: Define
int ParseLHCO::Define(stringstream &inputLine) {
stringstream copy(inputLine.str());
if(Parse::Define(copy)) return 1;
string block;
inputLine >> block;
if(block == "lhco_input") {
string type, option;
int val;
inputLine >> option;
LHCOInputs.push_back(new LHCOInfo(option));
while(!inputLine.eof()) {
inputLine >> type;
if(type != "MET") inputLine >> val;
else val = -1;
LHCOInputs.back() -> AddSubInput(type, val);
}
示例13: ParseSettings
void MesenMovie::ParseSettings(stringstream &data)
{
while(!data.eof()) {
string line;
std::getline(data, line);
if(!line.empty()) {
size_t index = line.find_first_of(' ');
if(index != string::npos) {
string name = line.substr(0, index);
string value = line.substr(index + 1);
if(name == "Cheat") {
_cheats.push_back(value);
} else {
_settings[name] = value;
}
}
}
}
}
示例14: catch
/*
* NOW WITH STRING STREAM SUPPORT!
*/
DataLine::DataLine(stringstream &inStream,int position) {
this->position = position;
while (inStream.peek()!='\n' && !inStream.eof()) {
//keep reading unless the end is reached.
string token = "";
inStream >> token;
cout << token << endl;
try {
float f = std::stof(token); //<works
//double d = std::stod(token);
//cout << f << endl;
theValues.push_back(f);
} catch (...) {
if (token != "") {
cout << "Error on: " << token << endl;
}
}
}
}
示例15: get_resistance
// function for reading the resistance from the stringstream. While it reads the
// DOUBLE it tests 3 various errors that can arrive from the user
// I set an arbitrary return of -1 for an error occurrence so my function calls
// know if it failed, if not it returns the desired input
double get_resistance (stringstream &ss){
double i;
ss >> i;
// check for invalid number my making sure it was read, and also making sure
// if the stored type into the variable matches and also checks to make sure
// the input is not a double or if a character follows the integer
if ((ss.fail() && !(ss.eof()))){
cout << "Error: argument is not a number" <<endl;
return -1;
}
// checks to see if the resistance was negative
else if (i < 0.0){
cout << "Error: invalid resistance (negative)" << endl;
return -1;
}
// this check tells us if an input was read
else if (ss.fail())
{
cout << "Error: missing argument" << endl;
return -1;
}
return i;
}