fix: open file as binary-mode #16

to avoid inconsistency between file size (obtained by tellg) and the
size of the actual contents that would be read later
This commit is contained in:
ToruNiina
2019-02-13 19:18:09 +09:00
parent 53f6b8268b
commit dd9319245e
3 changed files with 36 additions and 2 deletions

View File

@@ -42,8 +42,14 @@ In the case of file open error, it will throw `std::runtime_error`.
You can also pass a `stream` to the `toml::parse` function after checking the status.
Note that on __Windows OS__, stream that is opened as text-mode automatically converts
CRLF ("\r\n") into LF ("\n") and this leads inconsistency between file size and
the contents that would be read. This causes weird error. To use a file stream
with `toml::parse`, don't forget to pass binary mode flag when you open the
stream.
```cpp
std::ifstream ifs("sample.toml");
std::ifstream ifs("sample.toml", std::ios_base::binary);
assert(ifs.good());
const auto data = toml::parse(ifs /*, "filename" (optional)*/);
```