Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Changes
Page history
Update cpp
authored
Oct 02, 2023
by
umaumax
Show whitespace changes
Inline
Side-by-side
cpp.md
View page @
c95af41a
...
...
@@ -1860,6 +1860,7 @@ bool IsFileExist(const std::string &filename) {
*
[
c++ - How to read a binary file into a vector of unsigned chars - Stack Overflow
](
https://stackoverflow.com/questions/15138353/how-to-read-a-binary-file-into-a-vector-of-unsigned-chars
)
*
なぜか、
`std::istream_iterator`
を利用すると、ファイルの読み込みサイズが小さくなってしまう現象が発生した
*
理由は
`\n`
をスキップして
`std::vector`
へ保存してしまうためである
*
`std::istreambuf_iterator`
には
`uint8_t`
は指定できない
```
cpp
...
...
@@ -1902,21 +1903,33 @@ std::vector<uint8_t> LoadFileBad_istream_iterator(std::string& filepath) {
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
std
::
string
filepath
(
"./main"
);
std
::
string
filepath
(
"./main
.cpp
"
);
{
auto
goodVec
=
LoadFileGood
(
filepath
);
std
::
cout
<<
goodVec
.
size
()
<<
std
::
endl
;
for
(
auto
&
v
:
goodVec
)
{
std
::
cout
<<
v
;
}
std
::
cout
<<
std
::
endl
;
}
{
auto
goodVec
=
LoadFileGood_istreambuf_iterator
(
filepath
);
std
::
cout
<<
goodVec
.
size
()
<<
std
::
endl
;
for
(
auto
&
v
:
goodVec
)
{
std
::
cout
<<
v
;
}
std
::
cout
<<
std
::
endl
;
}
{
auto
badVec
=
LoadFileBad_istream_iterator
(
filepath
);
std
::
cout
<<
badVec
.
size
()
<<
std
::
endl
;
for
(
auto
&
v
:
badVec
)
{
std
::
cout
<<
v
;
}
std
::
cout
<<
std
::
endl
;
}
return
0
;
}
...
...
...
...