how to read a binary file from a path?

Hello all, just wondering if you can help me out here? I was given a specified path which i need to open in binary and put it into an array.


/home/turing/abyrnes/input/cs241/fall10/lincoln
is the path of the binary file

this is what I have written, but i get a ton of errors about "stray /### in program"


#include <fstream>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <math.h>
#include "Name.h"
#include "Date.h"
#include "Person.h"
#include "/home/turing/abyrnes/input/cs241/fall10/lincoln"

using namespace std;
using std::cout;
using std::endl;

int read_persons();

int main()
{
int count = 0;
cout << count;
cout << endl;
count = read_persons();
cout << count;
cout << endl;
return 0;
}


int read_persons()
{
int counts = 0;
int x = 8;
char names[100];


ifstream instream;
instream.open("lincoln.bin", ios::binary);
assert(instream);

while(instream)
{
counts = counts + 1;
instream.read((char *) &names[counts], sizeof names);
cout << names[counts];
cout << endl;
}
What's the problem?
I'm not really sure what you think this does:
 
#include "/home/turing/abyrnes/input/cs241/fall10/lincoln" 

But I am guessing its not what you expect... ;o)

You shouldn't really be treating your binary file as part of your source code. You should be using your source code to read the binary file. So don't include it with the #include.

Try this:
 
instream.open("/home/turing/abyrnes/input/cs241/fall10/lincoln", ios::binary);

Topic archived. No new replies allowed.