Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3324004
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:22:12+00:00 2026-05-17T23:22:12+00:00

for my assignment I am building a heap, the data for the heap is

  • 0

for my assignment I am building a heap, the data for the heap is coming from a file. One of the functions is to get the data, but I am having trouble understanding the ifstream read() function and am getting quite a nasty error because of it this is what I have:

template<class T, class P>
void get_list(vector<T>& v, const char* file_loc, P func) { 
   T data;
   ifstream inFile;

   inFile.open("file_loc");
   if (!inFile) {
      cerr << "Error - unable to open input file\n";
      exit(1);
   }

   inFile.read( &data, sizeof(T));

   while (inFile) {
      inFile.read( &data, sizeof(T));
      insert(v,data,func);
   }

   inFile.close();
}

the error I am receiving is:

prog7.h:53: error: no matching function for call to 
‘std::basic_ifstream<char, std::char_traits<char> >::read(int*, long unsigned int)’
/usr/include/c++/4.3/istream:468: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,_Traits>::read(_CharT*, std::streamsize) 
[with _CharT = char,   _Traits = std::char_traits<char>]

any help would be much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:22:12+00:00Added an answer on May 17, 2026 at 11:22 pm

    The prototype for std::ifstream::read is

    istream& read ( char* s, streamsize n );
    

    So where you have

    inFile.read( &data, sizeof(T));
    

    should be

    inFile.read( (char*) &data, sizeof(T));
    

    However this assumes you are reading raw bytes from a binary file. If you are parsing a text file with the integers represented in decimal ascii characters you can just use

    inFile >> data;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an assignment in MASM32 Assembly and I almost completed it but
I am building a class hierarchy that uses SSE intrinsics functions and thus some
I'm building a comparator for an assignment, and I'm pulling my hair out because
I'm building a shopping cart for a school assignment. I'm pretty much there except
Possible Duplicate: Ruby Assignment Syntax I don't get the concept of an assignment method
For a school assignment I have to write x86 assembly code, except I can't
For my university assignment I have to design some basic managment system for sicknesses
For a database assignment I have to model a system for a school. Part
For my assignment I have been assigned the task of creating a DTD for
For my university assignment I have to make a networkable version of pacman. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.