Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: use of deleted function std::basic_ofstream (OpenCV and C++11) [duplicate]

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!

like image 972
user667804 Avatar asked Jan 08 '23 15:01

user667804


1 Answers

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?

like image 197
vsoftco Avatar answered Jan 30 '23 11:01

vsoftco