Advertisement
getivan

Space Remover - UTF-16 LE BOM (Unicode)

Sep 17th, 2021
1,391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <cassert>
  3. #include <codecvt>
  4. #include <fstream>
  5. #include <string>
  6. #include <algorithm>
  7.  
  8. using namespace std;
  9.  
  10. int main() {
  11.     //The input file:
  12.     //you just need to change it's value to access different files
  13.     string inputFileName = R"(permutations-contact-keyword-export.txt)";
  14.  
  15.     //The output file:
  16.     //No need to change anything here
  17.     string outFileName = "updated-" + inputFileName;
  18.  
  19.     //Delete the old file with the same name
  20.     remove(outFileName.c_str());
  21.     //Open the file that we need to modify
  22.     wifstream inFile(inputFileName);
  23.     std::locale inLoc(std::locale(inFile.getloc(), new std::codecvt_utf16<wchar_t, 0x10ffff, std::little_endian>));
  24.     inFile.imbue(inLoc);
  25.  
  26.     //Open the output file
  27.     wofstream outFile;
  28.     std::locale outLoc(std::locale(std::cout.getloc(), new std::codecvt_utf16<wchar_t, 0x10ffff, std::little_endian>));
  29.     outFile.imbue(outLoc);
  30.     outFile.open(outFileName, std::ios::binary);
  31.  
  32.     //Copy from input file to output file, removing spaces
  33.     std::remove_copy_if(std::istreambuf_iterator<wchar_t>(inFile), std::istreambuf_iterator<wchar_t>(), std::ostreambuf_iterator<wchar_t>(outFile), [](wchar_t c) { return c == L' '; });
  34.  
  35.     //Close input file
  36.     inFile.close();
  37.  
  38.     //Close the output file
  39.     outFile.close();
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement