本文整理汇总了C++中stringstream::peek方法的典型用法代码示例。如果您正苦于以下问题:C++ stringstream::peek方法的具体用法?C++ stringstream::peek怎么用?C++ stringstream::peek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stringstream
的用法示例。
在下文中一共展示了stringstream::peek方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: CIFReadValue
/// Read one value, whether it is numeric, string or text
string CIFReadValue(stringstream &in,char &lastc)
{
bool vv=false;//very verbose ?
string value("");
while(!isgraph(in.peek())) in.get(lastc);
while(in.peek()=='#')
{//discard these comments for now
string tmp;
getline(in,tmp);
lastc='\r';
while(!isgraph(in.peek())) in.get(lastc);
}
if(in.peek()=='_') {
if (vv)
cout << "WARNING: Trying to read a value but found a new tag !" << endl;
return value;
}
if(in.peek()==';')
{//SemiColonTextField
bool warning=!iseol(lastc);
if(warning)
cout<<"WARNING: Trying to read a SemiColonTextField but last char is not an end-of-line char !"<<endl;
value="";
in.get(lastc);
while(in.peek()!=';')
{
if (in.peek() == '_') {
cout << "WARNING: Trying to read a SemiColonTextField but found a new tag !" << endl;
warning = true;
break;
}
string tmp;
getline(in,tmp);
value+=tmp+" ";
}
if (!warning)
in.get(lastc);
if(vv) cout<<"SemiColonTextField:"<<value<<endl;
if(warning && !vv) cout<<"SemiColonTextField:"<<value<<endl;
return value;
}
if((in.peek()=='\'') || (in.peek()=='\"'))
{//QuotedString
char delim;
in.get(delim);
value="";
while(!((lastc==delim)&&(!isgraph(in.peek()))) )
{
in.get(lastc);
value+=lastc;
}
if(vv) cout<<"QuotedString:"<<value<<endl;
return value.substr(0,value.size()-1);
}
// If we got here, we have an ordinary value, numeric or unquoted string
in>>value;
if(vv) cout<<"NormalValue:"<<value<<endl;
return value;
}
示例3: trim
int Util::trim(stringstream &ss)
{
while(ss.peek()==' ')
ss.get();
return 0;
}
示例4: 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;
}
示例5: leeArbol
Arbin<Pieza> leeArbol(stringstream& ss) {
Arbin<Pieza> r;
if(ss.peek() == 'T') {
ss.get();
r = Arbin<Pieza>(leeArbol(ss), Pieza(), leeArbol(ss));
} else {
r = Arbin<Pieza>(Arbin<Pieza>(), tablaPiezas.consulta(ss.get()), Arbin<Pieza>());
}
}
示例6: 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;
}
}
}
}
示例7: getRule
unsigned int getRule(stringstream& ss, S2Setmap& pt2base, V2Imap& goodman) {
char c;
ss >> c;
assert(c == '(');
string sym = "";
ss >> sym;
unsigned int symI = sym2base[sym];
// printf("got symbol %s (%u)\n",sym.c_str(),symI);
vector<unsigned int> kSyms;
kSyms.push_back(symI);
while(true) {
c = ss.peek();
if(c == ' ') { //it's a space
ss.ignore(1); //ignore that space
} else if(c == '(') { //nonterminal
//get child node index
unsigned int index = getRule(ss,pt2base,goodman);
kSyms.push_back(index);
} else if (c == ')') {
ss.ignore(1); //burn closing paren
// printf("Finished Rule with sym %s and %lu kids\n",sym.c_str(),kSyms.size()-1);
unsigned int index = 0;
while(kSyms.size() > 3) { //try to add glue rule
// printf("K = %lu\n",kSyms.size());
unsigned int r = kSyms.back();
kSyms.pop_back();
unsigned int l = kSyms.back();
kSyms.pop_back();
unsigned int glueI = nSym*2;
vector<unsigned int> gluerule;
gluerule.push_back(glueI);//glue symbol
gluerule.push_back(l);
gluerule.push_back(r);
unsigned int glueindex = 0;
V2Imap::iterator fter = goodman.find(gluerule);
if(fter == goodman.end()) { //new node
goodman[gluerule] = goodmanIndex;
baseSym.push_back(glueI);
glueindex = goodmanIndex;
canL.push_back(false);
canR.push_back(false);
canL[l] = true;
canR[r] = true;
leftlook[l].push_back(make_pair(r,goodmanIndex));
bmap[make_pair(l,r)].insert(goodmanIndex);
goodmanIndex++;
} else { //seen it
glueindex = fter->second;
}
kSyms.push_back(glueindex);
}
V2Imap::iterator fter = goodman.find(kSyms);
if(fter == goodman.end()) { //new node
goodman[kSyms] = goodmanIndex;
baseSym.push_back(symI);
index = goodmanIndex;
canL.push_back(false);
canR.push_back(false);
goodmanIndex++;
if(kSyms.size() == 3) {
//add index -> l r
// printf("BR : %u -> %u %u\n",index,kSyms[1],kSyms[2]);
canL[kSyms[1]] = true;
canR[kSyms[2]] = true;
leftlook[kSyms[1]].push_back(make_pair(kSyms[2],index));
bmap[make_pair(kSyms[1],kSyms[2])].insert(index);
} else { //one child
//add index -> k
umap[kSyms[1]].insert(index);
//printf("UR : %u -> %u\n",index,kSyms[1]);
}
} else { //seen it
index = fter->second;
}
return index;
} else { //terminal
string term = "";
while(ss.peek() != ')') {
term += ss.get();
}
// printf("got terminal %s\n",term.c_str());
ss.ignore(1); //burn closing paren
//.........这里部分代码省略.........