에 저장하는 것은 정말 이상한 일입니다. 나는이 질문에 대한 답을 stackoverflow에서 찾지 못했습니다.<int>을
std::vector<int>
을 파일로 저장하려고합니다. std::ostreambuf_iterator<char>
파일에 쓰기 전에 char
에 v
의 각 값을 변환하는 것이 여기,
std::vector<int> v{0,1,2,4,8,16,32,64,128,256,512};
std::ofstream outfile("test.data", std::ios::out | std::ofstream::binary);
std::copy(v.begin(), v.end(), std::ostreambuf_iterator<char>(outfile));
outfile.close();
그러나 문제 : 다양한 장소에서 나는 다음과 같은 코드를 발견했다. 따라서 256
및 512
값은 0
으로 변경됩니다.
00000000 00 01 02 04 08 10 20 40 80 00 00
내 생각은 std::ostreambuf_iterator<int>
에 std::ostreambuf_iterator<char>
을 변경했다, 그러나 그것은 작동하지 않습니다 결과 파일은 hexedit에 따라 다음과 같습니다. 컴파일러에서 다음 오류를 throw합니다.
error: no matching function for call to ‘std::ostreambuf_iterator<int>::ostreambuf_iterator(std::ofstream&)’
std::copy(v.begin(), v.end(), std::ostreambuf_iterator<int>(outfile));
이 문제를 해결하려면 어떻게합니까?
'사용법 #include'와'사용법 #include '. 또한 아마도'#include ' –
Arunmu
@Arunmu 두 가지가 모두 포함됩니다. – user38034
단순히 | std :: ofstream :: binary'.어쨌든 바이너리 파일을 원하지 않습니다. –