How can I open binary file in C++?
I wanna open a text file.
thx!
How can I open binary file in C++?
I wanna open a text file.
thx!
#include <fstream.h>
ifstream File("MyFile.ext", ios::binary);
I believe it's something like this. Might be wrong though... I still use the old C file pointer way
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Not sure if this is what your after, but in its most basic form, i'd do it like this:
#include <fstream.h>
main()
{
char ch;
char filename[20] = "c:test.txt";
int mode = ios:ut;
fstream fout(filename, mode );
cout << "Ready for input, use CTRL+Z to end" << endl;
while ( cin.get( ch ) )
{
fout.put( ch );
}
fout.close();
return(0);
}
fout.close(); is important, miss it and you could **** up your whole hd.
to open the file:
#include <fstream.h>
main()
{
char ch;
char filename[20] = "c:test.txt";
int mode = ios::in;
fstream fin(filename, mode );
if (!fin)
cout << "Unable to open file";
while ( fin.get(ch) )
{
cout << ch;
}
fin.close();
return(0);
}