10.27 二进制打开文件漂亮

来源:互联网 发布:c语言的自定义函数 编辑:程序博客网 时间:2024/06/04 19:20
上代码//折磨一会子
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include<fstream>
#include <stack>
using namespace std;

int main() {
//    int num;
    ifstream fin("11", ios_base::binary);
    //
    //    // map<int,vector<string>   > m;
    //     string w;//最后输出
    //    while(fin>>num)
    //    {
    //
    //        for(int i=0;i<num;i++)
    //        {
    //        stack<char>q;
    //        string s2;
    //                while(fin>>s2)
    //                {
    //                        int l=s2.size();
    //                        for(int j=0;j<l;j++)
    //                            {
    //                              q.push(s2[j])    ;
    //                            }
    //                            for(int j=0;j<l;j++)
    //                            {
    //                                w+=q.top();
    //                                  q.pop();
    //                            }
    //                            w+=" ";
    //
    //                }
    //                w+='\n';
    //        }
    //    }
    //
    //    cout << w << endl; // prints !!!Hello World!!!
    int num;
    char ch;
    int l;
    string w;
    stack<char> q;
    fin >> num;
    fin.get(ch);
    for(int j=0;j<num;j++)
    {

        fin.get(ch);

        while (ch != '\n') {

            if (ch != ' ') {
                q.push(ch);
            }
            else
            {
                 l=q.size();
              for(int i=0;i<l;i++)
              {
                  w+=q.top();
                  q.pop();
              }
              w+=' ';
            }
            fin.get(ch);
        }
         for(int i=0;i<l;i++)
                      {
                          w+=q.top();
                          q.pop();
                      }
                      w+=' ';
    cout<<w;
    cout<<endl;
    w="";
    }

    cin >> num;

    return 0;
}


原创粉丝点击