Brick icon

File Commands

Brick | PRO | 07/11/16 12:02:02 PM UTC | 0 ⭐ | 227 👁️ | Never ⏰ | []
C++ |

1.01 KB

|

None

|

0 👍

/

0 👎

template <typename IterT>
void WriteFile(std::wstring             file,
               std::ios_base::openmode  mode,
               IterT                    begin,
               IterT                    end)
{
    std::copy(
        begin,
        end,
        std::ostreambuf_iterator<char>(std::ofstream(file, mode | std::ofstream::binary)));
}
 
template <typename IterT>
void CreateFile(std::wstring    file,
                IterT           begin,
                IterT           end)
{
    WriteFile(file, std::ios_base::trunc, begin, end);
}
 
void CopyFile(std::wstring  from,
              std::wstring  to)
{
    CreateFile(to,
               std::istreambuf_iterator<char>(std::ifstream(from, std::ios_base::binary)),
               std::istreambuf_iterator<char>());
}
 
std::vector<char> ReadFile(std::wstring file)
{
    return std::vector<char>
    (
        std::istreambuf_iterator<char>(std::ifstream(file, std::ios_base::binary)),
        std::istreambuf_iterator<char>()
    );
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎