入力ファイルが、それを読んでいるのと同じプラットフォームで生成されていると仮定します。
次に、ファイルをテキストモードで開くだけで、LTS(この場合は'\ r \ n'のようになります)を'\n'に変換できます。
std::ifstream testFile(inFileName);
remove_copy
アルゴリズムを使用して、特定の文字を削除できます。
std::vector<char> fileContents;
// Copy all elements that are not '\n'
std::remove_copy(std::istreambuf_iterator<char>(testFile), // src begin
std::istreambuf_iterator<char>(), // src end
std::back_inserter(fileContents), // dst begin
'\n'); // element to remove
複数のタイプの文字を削除する必要がある場合は、ファンクターを作成してremove_copy_if
アルゴリズムを使用する必要があります。
struct DelNLorCR
{
bool operator()(char x) const {return x=='\n' || x=='\r';}
};
std::remove_copy_if(std::istreambuf_iterator<char>(testFile), // src begin
std::istreambuf_iterator<char>(), // src end
std::back_inserter(fileContents), // dst begin
DelNLorCR()); // functor describing bad characters