In class weve been shown how to read from a binary file and read from a text file but Im unsure how to write text to a binary file?
Heres my attempt so far,
Can you help?
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
FILE *namefile = NULL;
char line[35];
namefile = fopen( "s:\names.dat", "wb");
fwrite(line, sizeof( line ),35,namefile);
while (feof( namefile ) == 0)
{
cout << "Name1" << endl;
cout << "Name2" << endl;
cout << "Name3" << endl;
cout << "Name4" << endl;
cout << "Name5" << endl;
fwrite(&line, sizeof( line ),35,namefile);
}
fclose( namefile );
cin.ignore;
cin.get();
}
Thanks for any reply.