zoukankan      html  css  js  c++  java
  • C++ fstream stringstream

    一、文件输入输出

    C/C++

    输入:

    freopen("in.cpp", "r", stdin);
    fclose(stdin);

    输出:

    freopen("in.cpp", "r", stdout);
    fclose(stdout);

    C++

    输入:

    ifstream cin("in.cpp");

    cin.close();

    输出:

    ofstream cout("out.cpp");

    cout.close();

    二、istringstream ostringstream 和 stringstream.

    常用函数:

    string str, s;
    
    stringstream str;
    
    stringstring str(s);
    
    str.clear();
    
    str.str(s);

    Eg:

    #include <sstream>
    #include <iostream>
    #include <stdio.h>
    #include <fstream>
    using namespace std;
    
    string str, name, pnum;
    string outstr;
    
    int main() {
        ifstream cin("in.cpp");
        ofstream cout("out.cpp");
        stringstream imess;
        stringstream omess;
        while (getline(cin, str)){
            imess.clear();
            omess.str("");
            imess.str(str);
    
            imess >> name;
            omess << name << ":";
    
            while(imess >> pnum) {
                omess << " " << pnum;
            }
            cout << omess.str() << endl;
        }
        cin.close();
        cout.close();
        return 0;
    }
    
  • 相关阅读:
    z-index优先级小结
    如何消除img间的默认间隙
    text-align和vertical-align
    HTTP
    HTTP
    HTTP
    HTTP
    ES6标准入门
    ES6标准入门
    ES6标准入门
  • 原文地址:https://www.cnblogs.com/icode-girl/p/5734296.html
Copyright © 2011-2022 走看看