本文整理汇总了C++中stringstream::putback方法的典型用法代码示例。如果您正苦于以下问题:C++ stringstream::putback方法的具体用法?C++ stringstream::putback怎么用?C++ stringstream::putback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stringstream
的用法示例。
在下文中一共展示了stringstream::putback方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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 {
示例3: Revc
void Revc(string &str, stringstream &strIn) {
for (int i = (int)str.size()-1; i >= 0; i--) {
strIn.putback(str[i]);
}
}
示例4: readFloat
int readFloat(string &res, stringstream &strIn) {
// cout << strIn.str() << endl;
res = "";
char ch;
while (~(ch = strIn.get()) &&
(ch == ' ' || ch == '\n' || ch == '\t')) {
;
}
if (strIn.eof()) return END;
if (ch != '.' && ch != '+' && ch != '-' && !(ch <= '9' && ch >= '0')) {
return ERR;
}
if (ch == '.') {
res += ch;
if ((ch = strIn.get()) == -1 || !isdigit(ch)) {
if (!strIn.eof()) {
strIn.putback(ch);
}
strIn.putback(res[0]);
return ERR;
} else {
// cout << res << endl;
strIn.putback(ch);
// cout << ch << endl;
readInt(res, strIn, false);
// cout << res << endl;
if ((ch = strIn.get()) == -1 || ch != 'e') {
if (!strIn.eof()) {
strIn.putback(ch);
}
return OKAY;
} else {
res += ch;
if ((ch = strIn.get()) == -1 || !(ch == '+' || ch == '-' || isdigit(ch))) {
return ERR;
} else {
strIn.putback(ch);
if (readInt(res, strIn, false) == ERR) return ERR;
}
}
}
} else if (isdigit(ch)) {
strIn.putback(ch);
readInt(res, strIn, false);
if ((ch = strIn.get()) == -1 || ch != '.') {
if (ch != 'e') {
if (ch != -1)
strIn.putback(ch);
Revc(res, strIn);
return ERR;
} else {
res += ch;
if ((ch = strIn.get()) == -1 || !(ch == '+' || ch == '-' || isdigit(ch))) {
return ERR;
} else {
strIn.putback(ch);
if (readInt(res, strIn, false) == ERR) return ERR;
}
}
} else {
res += ch;
if ((ch = strIn.get()) == -1) {
return OKAY;
} else if (isdigit(ch)) {
strIn.putback(ch);
readInt(res, strIn, false);
if ((ch = strIn.get()) == -1 || ch != 'e') {
if (!strIn.eof())strIn.putback(ch);
return OKAY;
} else {
res += ch;
if ((ch = strIn.get()) == -1 || !(ch == '+' || ch == '-' || isdigit(ch))) {
return ERR;
} else {
strIn.putback(ch);
if (readInt(res, strIn, false) == ERR) return ERR;
}
}
} else if (ch == 'e') {
res += ch;
if ((ch = strIn.get()) == -1 || !(ch == '+' || ch == '-' || isdigit(ch))) {
return ERR;
} else {
strIn.putback(ch);
if (readInt(res, strIn, false) == ERR) return ERR;
}
} else {
strIn.putback(ch);
return OKAY;
}
}
} else {
}
return OKAY;
//.........这里部分代码省略.........