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

  • SEARCH
  • Home
  • 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 8523247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:21:20+00:00 2026-06-11T07:21:20+00:00

Im trying to use this kind of iterators, but I have got errors for

  • 0

Im trying to use this kind of iterators, but I have got errors for the following code:

void linearMatrix::Write_File_Matrix(const char *Path)
{
    ofstream FILE(Path, std::ios::out | std::ofstream::binary);
    FILE.write(reinterpret_cast<const char *>(&myWidth), sizeof(float));
    FILE.write(reinterpret_cast<const char *>(&myHeight), sizeof(float));
    ostreambuf_iterator<float> out_it (FILE);
    copy(myVector.begin(), myVector.end(), out_it);
}

void linearMatrix::Read_File_Matrix(const char *Path)
{
    ifstream FILE(Path, std::ios::in | std::ifstream::binary);

    if(!FILE)
    {
        cerr << "Cannot open the file" << endl;
        exit(1);
    }
    FILE.read(reinterpret_cast<const char *>(&myWidth), sizeof(myWidth));
    FILE.read(reinterpret_cast<const char *>(&myHeight), sizeof(myHeight));
    istreambuf_iterator<float> iter(FILE);
    copy(iter.begin(), iter.end(), std::back_inserter(myVector));
}

The problems are:

1- ostreambuf_iterator<float> out_it (FILE);

error: invalid conversion from ‘void*’ to
‘std::ostreambuf_iterator::streambuf_type* {aka
std::basic_streambuf >*}’
[-fpermissive]

2- FILE.read(reinterpret_cast<const char *>(&myWidth), sizeof(myWidth));

error: invalid conversion from ‘const char*’ to ‘std::basic_istream::char_type* {aka char*}’ [-fpermissive]

3- FILE.read(reinterpret_cast<const char *>(&myHeight), sizeof(myHeight));

error: invalid conversion from ‘const char*’ to
‘std::basic_istream::char_type* {aka char*}’ [-fpermissive]

4- std::ifstream FILE(Path, std::ios::in | std::ifstream::binary);

error: invalid conversion from ‘void*’ to
‘std::ostreambuf_iterator::streambuf_type* {aka
std::basic_streambuf >*}’
[-fpermissive]

5- copy(iter.begin(), iter.end(), std::back_inserter(myVector));

error: ‘class std::istreambuf_iterator’ has no member named
‘begin’

error: ‘class std::istreambuf_iterator’ has no member named
‘end’

What am I doing wrong? I’m using the nsight eclipse from CUDA, but compiling a C++ project with g++. I refer to: Reading and writing a std::vector into a file correctly

#include <iostream>
#include <algorithm>
#include <iterator>
#include <fstream>
#include <vector>

using namespace std;

void Write_File_Matrix(const char *Path)
{
    float myWidth = 0;
    float myHeight = 0;
    vector<float> v;
    v[0] = 1;
    v[1] = 2;
    v[2] = 3;
    ofstream outFILE(Path, ios::out | ofstream::binary);
    outFILE.write(reinterpret_cast<const char *>(&myWidth), sizeof(float));
    outFILE.write(reinterpret_cast<const char *>(&myHeight), sizeof(float));
    ostreambuf_iterator<float> out_it (outFILE);
    copy(V.begin(), V.end(), out_it);
}

void Read_File_Matrix(const char *Path)
{
    float myWidth = 0;
    float myHeight = 0;
    vector<float> v;

    ifstream inFILE(Path, ios::in | ifstream::binary);

    if(!inFILE)
    {
        cerr << "Cannot open the file" << endl;
        exit(1);
    }
    inFILE.read(reinterpret_cast<const char *>(&myWidth), sizeof(myWidth));
    inFILE.read(reinterpret_cast<const char *>(&myHeight), sizeof(myHeight));
    istreambuf_iterator<float> iter(inFILE);
    copy(iter.begin(), iter.end(), std::back_inserter(myVector));
}

int main() {

    Write_File_Matrix("M.dat");
    Read_File_Matrix("R.dat");

    return 0;
}
  • 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-06-11T07:21:22+00:00Added an answer on June 11, 2026 at 7:21 am

    1- ostreambuf_iterator out_it (FILE);

    error: invalid conversion from ‘void*’ to ‘std::ostreambuf_iterator::streambuf_type* {aka std::basic_streambuf >*}’ [-fpermissive]

    std::ostreambuf_iterator takes as template parameter the character type of the stream, NOT the type you want to convert to. Try:

    std::ostreambuf_iterator<char> out_it(FILE);
    

    Ditto for #4.


    EDIT: Let’s solve your big problem instead of your small ones:

    Don’t bother with iterators, just write the vector data out all in one go:

    void Write_File_Matrix(const char *Path)
    {
        float myWidth = 0;
        float myHeight = 0;
        vector<float> v;
        v[0] = 1;
        v[1] = 2;
        v[2] = 3;
        ofstream outFILE(Path, ios::out | ofstream::binary);
        outFILE.write(reinterpret_cast<const char *>(&myWidth), sizeof(float));
        outFILE.write(reinterpret_cast<const char *>(&myHeight), sizeof(float));
        outFile.write(reinterpret_cast<const char *>(&v[0]), v.size()*sizeof(float));
    }
    

    Reading, however, still needs to be one-piece-at-a-time.

    void Read_File_Matrix(const char *Path)
    {
        float myWidth = 0;
        float myHeight = 0;
        vector<float> v;
    
        ifstream inFILE(Path, ios::in | ifstream::binary);
    
        if(!inFILE)
        {
            cerr << "Cannot open the file" << endl;
            exit(1);
        }
        inFILE.read(reinterpret_cast<char *>(&myWidth), sizeof(myWidth));
        inFILE.read(reinterpret_cast<char *>(&myHeight), sizeof(myHeight));
        float f;
        while( inFILE.read(reinterpret_cast<char *>(&f), sizeof(f)))
          v.push_back(f);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an example of what I'm trying to ask. I use this kind
Trying to use this code to connect the AD PrincipalContext context = new PrincipalContext(ContextType.Domain,
I'm trying to use this to create a splash screen, but I only get
I'm actualilly trying tu use this nice widget : http://quasipartikel.at/multiselect_next/ I have two of
i am trying to use this code: <%= File.ReadAllText(Server.MapPath(Members/newsletters/welcome.html))%> which works great but now
im trying to apply this kind of notification with my website. but was wondering
Edit: To be clear, I'm trying to use this kind of generator (i.e. with
Trying to use this method (gist of which is use self.method_name in the FunnyHelper
trying to use this route: from(activemq:profiles).aggregate(header(cheese)).batchSize(30).bean(ProfilesQueueService, saveContacts) Fails with: No signature of method: org.apache.camel.model.RouteType.aggregate()
Im trying to use this page slider jquery plugin, you can see the demo

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.