Advertisement
zhangsongcui

Replace tab, space

Jul 22nd, 2011
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. //g++ 4.6.1编译通过!
  2. #include <fstream>
  3. #include <iostream>
  4. #include <algorithm>
  5. #include <iterator>
  6. #include <string>
  7.  
  8. int main(int argc, char** argv)
  9. {
  10.     using namespace std;
  11.     if (argc!=2)
  12.     {
  13.         clog << "\t防河蟹——空格、制表符替换程序" << endl;
  14.         clog << "用法:" << argv[0] << " 程序名" << endl;
  15.         clog << "在Windows下,您可以简单的将所需替换的原代码文件拖到本程序上" << endl;
  16.         return 1;
  17.     }
  18.     ifstream fileIn(argv[1]);
  19.     if (!fileIn.is_open())
  20.     {
  21.         cerr << "打开文件失败!" << endl;
  22.         return 1;
  23.     }
  24.  
  25.     string filename(argv[1]);
  26.     filename.insert(filename.rfind('.'), ".Modified");
  27.     ofstream fileOut(filename.c_str());
  28.     for (istreambuf_iterator<char> ibeg(fileIn), iend; ibeg != iend; ++ibeg)
  29.     {
  30.         switch (*ibeg)
  31.         {
  32.         case ' ':
  33.             fileOut << "&#160;";
  34.             break;
  35.         case '\t':
  36.             fileOut << "&#160;&#160;&#160;&#160;";
  37.             break;
  38.         default:
  39.             fileOut << *ibeg;
  40.             break;
  41.         }
  42.     }
  43.     clog << "目标文件“" << filename << "”已生成!" << endl;
  44.     clog << "替换完成!" << endl << "请使用贴吧经典版发帖!" << endl;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement