当前位置: 首页>>代码示例>>C++>>正文


C++ stringstream::putback方法代码示例

本文整理汇总了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;
}
开发者ID:rootial,项目名称:Compiler,代码行数:35,代码来源:main.cpp

示例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 {
开发者ID:rootial,项目名称:Compiler,代码行数:32,代码来源:main.cpp

示例3: Revc

void Revc(string &str, stringstream &strIn) {
    for (int i = (int)str.size()-1; i >= 0; i--) {
        strIn.putback(str[i]);
    }
}
开发者ID:rootial,项目名称:Compiler,代码行数:5,代码来源:main.cpp

示例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;
//.........这里部分代码省略.........
开发者ID:rootial,项目名称:Compiler,代码行数:101,代码来源:main.cpp


注:本文中的stringstream::putback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。