Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

5
Question about my fileHandler
Post Flair (click to view more posts with a particular flair)
Post Body

I've created a file handler function for an assignment which accesses a binary file, takes the int data from the file and passes it to an array.

The code is below. The problem I have is with the line "numElements = inFile.tellg() / sizeof(int);". When I compile the program, I'm getting a warning:

warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data

Is there anyone who can point me the way to a solution? the code still compiles and the function runs correctly, but I would like to resolve this issue.

 void fileHandler(ifstream &inFile, string &filename, int &numElements, int *&A)
    {
    inFile.open(filename, ios::binary);
    if(inFile.is_open()){
        inFile.seekg(0, ios::end);
        numElements = inFile.tellg() / sizeof(int);
        inFile.seekg(0, ios::beg);
        A = new int[numElements];
        inFile.read((char *)A, numElements * sizeof(int));
        inFile.close();
    } else{
        cerr << "Error opening file. Exiting program." << endl;
        exit(0);
    }
}

Author
User Disabled
Account Strength
0%
Disabled 1 year ago
Account Age
2 years
Verified Email
Yes
Verified Flair
No
Total Karma
688
Link Karma
505
Comment Karma
183
Profile updated: 22 hours ago
Posts updated: 1 year ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
2 years ago