istreambuf_iterator and bom #include #include #include #include #include #include using namespace std; int main() { //The input file: istreambuf_iterator and bom How to get it? istreambuf_iterator and bom //you just need to change it's value to access different files string inputFileName = R"(permutations-contact-keyword-export.txt)"; //The output file: //No need to change anything here string outFileName = "updated-" + inputFileName; //Delete the old file with the same name remove(outFileName.c_str()); //Open the file that we need to modify istreambuf_iterator and bom How to get it? istreambuf_iterator and bom wifstream inFile(inputFileName); std::locale inLoc(std::locale(inFile.getloc(), new std::codecvt_utf16)); inFile.imbue(inLoc); //Open the output file wofstream outFile; std::locale outLoc(std::locale(std::cout.getloc(), new std::codecvt_utf16)); outFile.imbue(outLoc); outFile.open(outFileName, std::ios::binary); istreambuf_iterator and bom How to use it? istreambuf_iterator and bom //Copy from input file to output file, removing spaces std::remove_copy_if(std::istreambuf_iterator(inFile), std::istreambuf_iterator(), std::ostreambuf_iterator(outFile), [](wchar_t c) { return c == L' '; }); //Close input file inFile.close(); //Close the output file outFile.close(); } istreambuf_iterator and bom How to use it? istreambuf_iterator and bom istreambuf_iterator and bom