4

I'm trying to import a project that I wrote some time ago under Windows using C++11 and OpenCV but it is giving me troubles and I can't figure out why. It is a MakeFile project and I added a line to enable C++11 support. However, when I'm trying to run "make" or run the project in eclipse I receive the following error (and a few others)

use of deleted function β€˜std::basic_filebuf<char>&  std::basic_filebuf<char>::operator=(const std::basic_filebuf<char>&)’   FacadeLabelingV2        line 599, external location: /usr/include/c++/4.8/fstream

My code looks like this:

#ifndef _FILEUTIL_CPP_
#define _FILEUTIL_CPP_

#include "Configuration.h"
#include "Utilities.cpp"

#include <iostream>
#include <fstream>


static void saveFeatures(const std::pair<cv::Mat, cv::Mat>& features, const Configuration& config, bool training, bool append, int counter = 0){
    string prefix;
    if (training) {
        prefix = "train";
    } else {
        prefix = "test";
    }
    std::string directory = config.dir_classifiers + config.name_of_run;
    std::ofstream save_file;
    std::string counter_appendix = std::to_string(counter / 50);
    std::string path_temp = directory + prefix + "_features" + counter_appendix + ".txt";
    if (append){
        save_file = std::ofstream(path_temp, std::fstream::app);
...

I think it could be a problem with OpenCV not using C++11, is that possible? How could I fix that? I'm pretty sure this code was working on my windows machine without any problems.

Thank you very much!

user667804
  • 740
  • 6
  • 25
  • 1
    Use `.open()`. The libstdc++ that comes with gcc 4.x has not implemented moveable streams yet; see https://stackoverflow.com/questions/27878495/ofstream-not-working-on-linux – Wintermute Mar 28 '15 at 17:37
  • Thanks! Open() works great, sorry for this duplicated, tried to search but couldn't find the correct topic – user667804 Mar 28 '15 at 17:41

1 Answers1

9

The line

save_file = std::ofstream(path_temp, std::fstream::app);

should invoke the move operator=, since the rhs is a prvalue. So in principle it should work. However, there seems to be a bug in gcc < 5.0 implementations,

Why can't I move std::ofstream?

Community
  • 1
  • 1
vsoftco
  • 55,410
  • 12
  • 139
  • 252