std::map<std::string, std::ofstream> Map;
std::string name="name";
std::ofstream ofs(name,std::ios::app);
Map[name] = std::move(ofs);
我运行上面的代码,但失败了。 我使用-std = C++ 11在Ubuntu12.04和g ++-5(gcc版本5.4.1 20160904(Ubuntu 5.4.1-2ubuntu1〜12.04))上通过g ++ 4.9进行编译,它在下面引入了相同的错误消息。误差:使用删除功能的“标准:: basic_ofstream <char>&的std :: basic_ofstream <char> ::运算符=(常量的std :: basic_ofstream <char>&)”的ofstream删除
error: use of deleted function ‘std::basic_ofstream& std::basic_ofstream::operator=(const std::basic_ofstream&)’ Map[name] = std::move(ofs);
/usr/include/c++/4.9/fstream:602:11: note: ‘std::basic_ofstream& std::basic_ofstream::operator=(const std::basic_ofstream&)’ is implicitly deleted because the default definition would be ill-formed: class basic_ofstream : public basic_ostream<_CharT,_Traits>
看起来是g ++版本特定的。用VS 2013和[g ++ - 5.1]构建(http://coliru.stacked-crooked.com/a/c83e8a3939ac3115)。 – acraig5075