Reputation: 1
This might be a very silly bug, but I am very confused to why my code is writing the specified data as ascii characters in the file and not in binary format? What am I missing? Most tutorials I read online followed this setup so I have to be missing something crucial. Any help is appreciated. Also the output in the file is "123456"
void MipsInterpret::outFile() {
std::cout << "Writing file" << std::endl;
std::ofstream myFile;
myFile.open(outputFile, std::ios::binary);
if (!myFile) {
std::cerr << outputFile << " failed to open. Closing " << std::endl;
exit(1);
}
std::string test = "add $1, $2, $3";
char list[6] = {'1', '2', '3', '4', '5','6'};
myFile.write(list, 6);
if (!myFile.good()) {
std::cerr << "Error occurred at writing time!" << std::endl;
exit(1);
}
myFile.close();
}
Upvotes: 0
Views: 334
Reputation: 391
Insted of
char list[6] = {'1', '2', '3', '4', '5','6'};
do
char list[6] = {1, 2, 3, 4, 5, 6};
That will fix the issue because '1' is actually 49 in binary
Upvotes: 1