vendredi 18 août 2017

C++ map of a key and file doesn't work

I want to create a map of a key and the corresponding file in C++. I used the below snipper, which is giving me compilation error.

    std::map<std::string, std::ofstream> m_jsTabFilesMap;
    std::ofstream f1;
    std::string key = "a";
    m_jsTabFilesMap.insert({ key, f1 });

Build error:

1>------ Build started: Project: ExpApp5, Configuration: Debug Win32 ------
1>  EXpAppSource.cpp
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\utility(144): error C2280: 'std::basic_ofstream<char,std::char_traits<char>>::basic_ofstream(const std::basic_ofstream<char,std::char_traits<char>> &)' : attempting to reference a deleted function
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\fstream(1016) : see declaration of 'std::basic_ofstream<char,std::char_traits<char>>::basic_ofstream'
1>          c:\users\xyz\documents\visual studio 2013\projects\expapp5\expappsource.cpp(24) : see reference to function template instantiation 'std::pair<const _Kty,_Ty>::pair<std::string&,std::ofstream&,void>(_Other1,_Other2)' being compiled
1>          with
1>          [
1>              _Kty=std::string
1>  ,            _Ty=std::ofstream
1>  ,            _Other1=std::string &
1>  ,            _Other2=std::ofstream &
1>          ]
1>          c:\users\xyz\documents\visual studio 2013\projects\expapp5\expappsource.cpp(24) : see reference to function template instantiation 'std::pair<const _Kty,_Ty>::pair<std::string&,std::ofstream&,void>(_Other1,_Other2)' being compiled
1>          with
1>          [
1>              _Kty=std::string
1>  ,            _Ty=std::ofstream
1>  ,            _Other1=std::string &
1>  ,            _Other2=std::ofstream &
1>          ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Aucun commentaire:

Enregistrer un commentaire