Hey, I'm currently looking into steganography and I decided to create a C++ program to hide a txt file in a bmp file as a little learning experience. All this code runs fine, my problem is occurs when saving the fixed BMP data to file. I'm using the MinGW compiler with msys. I put some text to help with debugging:
Code:
std::cout << "Processing data";
//Function calls to process data go here (i won't go into it.)
std::cout << "Done!" << std::endl;
std::cout << "-----------------------------------------" << std::endl;
std::cout << "Saving to file...";
OutToFile(); //This function saves the data to a new bmp file.
std::cout << "Done!" << std::endl;
When I run the program, my output is this ($ indicates prompt)
$ ./steg file.txt file.bmp
Processing Data...Done!
----------------------------------------------
Saving to file...
$
The program just ends. No stackdump or anything. Here is the OutToFile function:
Code:
void Steg::OutToFile() const{
ofstream f("final.bmp", ios::binary | ios::trunc); //Filestream for saving
//test for failure (Exception class exists)
if(!f) { throw Hiding::Exception(); }
f.write(finalBMP.c_str(), finalBMP.size());
f.close();
std::cout << "Done!" << std::endl;
}
The exception is not thrown. (the try and catch are located in my main() function)
I tried removing everything from the function and placing this in it.
Code:
std::cout << "Testing" << std::endl;
The program then ran correctly, so I added this.
Code:
ofstream f("final.bmp", ios::binary | ios::trunc); //Filestream for saving
And the program failed again. Does anyone have a clue what's happening? I have included the correct headers and using directives because the ifstreams at the start of the program work fine. It's simply when I open this new ofstream that the program just stops in it's tracks and exits.