How to open floppy disc with fstream?
I’m trying something like this:
but it always returns error
#include <iostream>
#include <fstream>
using namespace std;
char a='k';
int main()
{
fstream stream;
stream.open( "\\\\.\\A:", ios::binary );
if( stream.good() == false )
{
cout <<"Error";
}
for( int i = 0 ; i < 512 ; i++ )
{
stream >> a;
//cout << a;
}
stream.close();
cin.get();
return 0;
}
You cannot use fstream to open a device – only a file within the filesystem contained on that device. You need to use operating system specific functionality to access a device.
EDIT: To be clear, it might be possible to open the floppy device using fstream but this level of access to the system goes beyond the level of abstraction provided by the Standard C++ Library and so OS-specific functions should be used instead.