Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++11 错误:使用已删除的函数‘;std::流的基本单元<;char>&;std::流的基本单元<;char>;::运算符=(const std::basic_of stream<;char>;)&x2019;删除的流 std::map; std::string name=“name”; 流ofs的std::of(名称,std::ios::app); Map[name]=std::move(ofs);_C++11_G++ - Fatal编程技术网

C++11 错误:使用已删除的函数‘;std::流的基本单元<;char>&;std::流的基本单元<;char>;::运算符=(const std::basic_of stream<;char>;)&x2019;删除的流 std::map; std::string name=“name”; 流ofs的std::of(名称,std::ios::app); Map[name]=std::move(ofs);

C++11 错误:使用已删除的函数‘;std::流的基本单元<;char>&;std::流的基本单元<;char>;::运算符=(const std::basic_of stream<;char>;)&x2019;删除的流 std::map; std::string name=“name”; 流ofs的std::of(名称,std::ios::app); Map[name]=std::move(ofs);,c++11,g++,C++11,G++,我运行了上面的代码,但失败了。 我在Ubuntu12.04和g++-5(gcc版本5.4.1 20160904(Ubuntu5.4.1-2ubuntu1~12.04))上用g++4.9编译了它,使用-std=c++11,这会导致下面相同的错误消息 错误:使用已删除的函数“std::basic_of stream”& std::basic_of stream::operator=(常量) std::basic_of stream&)'Map[name]=std::move(ofs) /usr/in

我运行了上面的代码,但失败了。 我在Ubuntu12.04和g++-5(gcc版本5.4.1 20160904(Ubuntu5.4.1-2ubuntu1~12.04))上用g++4.9编译了它,使用-std=c++11,这会导致下面相同的错误消息

错误:使用已删除的函数“std::basic_of stream”& std::basic_of stream::operator=(常量) std::basic_of stream&)'Map[name]=std::move(ofs)

/usr/include/c++/4.9/fstream:602:11:注意:'std::basic_of stream& std::basic_of stream::operator=(常量) std::basic_of stream&)被隐式删除,因为默认 定义将是格式错误的: 流的基本类:公共基本类


GCC 5.1中添加了对移动iostreams的支持,因此您不能使用GCC 4.9。这在4.9版的libstdc++手册中有记录:

27.5 | Iostreams基类|部分|基本| ios上缺少移动和交换操作。缺少io_errc和iostream_类别。ios_base::失败不是由系统_错误派生的。缺少ios_基::hexfloat。
27.6 |流缓冲区| Y |
27.7 |格式化和操纵器|部分|缺少移动和交换操作缺少get|u time和put|u time操纵器。
27.8 |基于字符串的流|部分|缺少移动和交换操作
27.9 |基于文件的流|部分|缺少移动和交换操作


它在GCC 5.x中受支持,工作正常,因此您一定是做错了什么(可能忘记使用
-std=c++11
,或者将其指向4.9标题,这肯定不起作用)。

看起来是特定于g++版本的。使用VS 2013和。
std::map<std::string, std::ofstream> Map;
std::string name="name";
std::ofstream ofs(name,std::ios::app);
Map[name] = std::move(ofs);