Reading and writing binary file

If you want to do this the C++ way, do it like this: #include <fstream> #include <iterator> #include <algorithm> int main() { std::ifstream input( “C:\\Final.gif”, std::ios::binary ); std::ofstream output( “C:\\myfile.gif”, std::ios::binary ); std::copy( std::istreambuf_iterator<char>(input), std::istreambuf_iterator<char>( ), std::ostreambuf_iterator<char>(output)); } If you need that data in a buffer to modify it or something, do this: #include <fstream> … Read more

How to clear input buffer in C?

The program will not work properly because at Line 1, when the user presses Enter, it will leave in the input buffer 2 character: Enter key (ASCII code 13) and \n (ASCII code 10). Therefore, at Line 2, it will read the \n and will not wait for the user to enter a character. The … Read more