代码格式化

· · 算法·理论

#include<bits/stdc++.h>
using namespace std;
int main(){
    cout<<"把要格式化的代码放在本代码同路径下,命名为text.cpp,fmtext.cpp为本代码格式化后的输出文件!\n";
    system("pause"); 
    freopen("text.cpp","r",stdin);
    freopen("fmtext.cpp","w",stdout);
    int tabs=0;
    string xxs;
    while(1){
        getline(cin,xxs);
        if(xxs[0]=='}'){
            tabs--;
        }
        for(int i=1;i<=tabs;i++){
            cout<<"  ";
        }
        if(xxs[xxs.size()-1]=='{'){
            tabs++;
        }
        if(xxs.size()>0){
            cout<<xxs<<endl;
        }
    }
}