Question

For an assignment I have been asked to read in from two separate .dat files. I have been using ifstreams to do this, but at when I try to build I get the following error message: /usr/include/c++/4.8/bits/ios_base.h:786:5: error: ‘std::ios_base::ios_base(const std::ios_base&)’ is private. I've managed to track the offending line down to this: NMEAobject fred = get_nmea_object(in_stream1);

Here is my header file

#ifndef NMEAINPUT_H
#define NMEAINPUT_H


class NMEAinput {
public:
NMEAinput(std::string fn1, std::string fn2);

private:
std::ifstream in_stream1;
std::ifstream in_stream2;
std::ofstream out_stream;

bool test_gsv(std::string in_gsv);
NMEAobject get_nmea_object(std::ifstream in);
NMEAobject read_rmc(std::string in_rmc);
std::string* split(std::string in_string,char split_point);
};

#endif  

and here is my cpp file:

#include <stdlib.h>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <list>
#include "NMEAobject.h"
#include "NMEAinput.h"
#include "GPXoutput.h"

NMEAinput::NMEAinput(std::string fn1, std::string fn2) {
in_stream1.open(fn1.c_str());
in_stream2.open(fn2.c_str());
out_stream.open("outfile.gpx");
if(!in_stream1||!in_stream2) {
    std::cout << "Error with data read";
}
std::list<NMEAobject> stream1;
std::list<NMEAobject> stream2;
NMEAobject fred = get_nmea_object(in_stream1);
stream1.push_back(fred);
stream2.push_back(get_nmea_object(in_stream2));
int stream_time = stream1.front().get_time();
stream1.pop_front();
stream1.push_back(get_nmea_object(in_stream1));
stream2.push_back(get_nmea_object(in_stream2));
GPXoutput out(out_stream);
while(!stream1.empty() && !stream2.empty()){
    if(stream1.front().get_time() - stream_time < 1){
        out.put(stream1.front().convert(),out_stream);
    }
    else{
        out.put(stream2.front().convert(),out_stream);
    }
    stream_time = stream1.front().get_time();
    stream1.pop_front();
    stream2.pop_front();
    stream1.push_back(get_nmea_object(in_stream1));
    stream2.push_back(get_nmea_object(in_stream2));*/
   // if(stream1.front() == std::NULL || stream2.front() == std::NULL) break;
}
}



NMEAobject NMEAinput::get_nmea_object(std::ifstream in_stream){
std::string line;
bool good_rmc = false;
bool good_gsv = true;
while(std::getline(in_stream,line)&&!good_rmc){
    std::string data_check = line.substr(0,3);
    if(data_check == "$GP"){
        data_check = line.substr(3,3);
        if(data_check == "GSV"){
            good_gsv = test_gsv(line);
        }
        else if (data_check =="RMC"&&good_gsv){
            NMEAobject out = read_rmc(line);
            good_rmc = true;
            return out;
        }
    } 
}

 }
Was it helpful?

Solution

iostreams are not copyable, but you're passing them by value:

NMEAobject get_nmea_object(std::ifstream in);  // Wrong

It should be replaced with:

NMEAobject get_nmea_object(std::ifstream& in);

The above now passes by reference, thus not incurring a copy.

Basically your issue boils down to doing this (try to compile this small program). You will see basically the same errors you're having now.

#include <fstream>
using namespace std;
int main()
{
    ifstream ifs1;
    ifstream ifs2;
    ifs1 = ifs2;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top