파일에 쓰기 전에 이진 데이터를 임시로 캐시하고 싶습니다. 이것은 내 생각이었다.파일에 이진 데이터 쓰기
헤더 다음에 오는 데이터의 양을 나타내는이 데이터 앞에 헤더를 삽입해야하므로이 데이터를 ofstream file
에 기록하기 전에이 데이터를 캐시에 보관하는 방법이 필요했습니다. 나는 ostream buffer();
을 작성하여 파일에 쓰지 않고이 모든 데이터를 덤프 할 수 있습니다.
헤더를 작성한 후 데이터를 덤프하려면 file << buffer
을 수행하면됩니다.
같은 일이 같이
error: no matching function for call to ‘TGA2Converter::writePixel(std::ostream (&)(), uint32_t&)’
note: candidate is: void TGA2Converter::writePixel(std::ostream&, uint32_t)
왜이 메시지는 무엇입니까? 그리고 아마도 더 중요한 것은, 제가 가장 효과적이고 편리한 방법으로 문제에 접근하고 있습니까?
편집 :명 코드를 요구하고있다. 나는
// This is a file. I do not want to write the binary
// data to the file before I can write the header.
ofstream file("test.txt", ios::binary);
// This is binary data. Each entry represents a byte.
// I want to write it to a temporary cache. In my
// real code, this data has to be gathered before
// I can write the header because its contents depend
// on the nature of the data.
stringstream cache;
vector<uint32_t> arbitraryBinData;
arbitraryBinData.resize(3);
arbitraryBinData[0] = 0x00;
arbitraryBinData[1] = 0xef;
arbitraryBinData[2] = 0x08;
// Write it to temporary cache
for (unsigned i = 0; i < arbitraryBinData.size(); ++i)
cache << arbitraryBinData[i];
// Write header
uint32_t header = 0x80; // Calculation based on the data!
file << header;
// Write data from cache
file << cache;
나는 완전히 파일에 기록이 이진 데이터를 예상 ...이로 범위를 좁힐려고 :
0000000: 8000 ef08
하지만이있어 :
0000000: 3132 3830 7837 6666 6638 6434 3764 3139
0000010: 38
을 예상되는 결과를 얻지 못하는 이유는 무엇입니까?
몇 가지 코드를 게시하십시오. –
질문을 업데이트했습니다. 바라기를 바꿔서 내가하려는 일을 해소 해 주겠다. – Pieter