#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;
}
}
}代码格式化
文章信息与版本
文章信息
- 发布
- 2025年12月9日
- 收录
- 2026年9月9日
- 更新
- 2026年11月21日
- 篇幅
- 约 1 分钟