2017-03-29 1 views
1
std::map<std::string, std::ofstream> Map; 
std::string name="name"; 
std::ofstream ofs(name,std::ios::app); 
Map[name] = std::move(ofs); 

을 삭제 ofstream. -std = C++ 11을 사용하여 Ubuntu12.04 및 g ++ - 5 (gcc 버전 5.4.1 20160904 (Ubuntu 5.4.1-2ubuntu1 ~ 12.04))에서 g ++ 4.9로 컴파일했습니다. 그러면 아래와 같은 오류 메시지가 나타납니다. IOSTREAMS를 이동오류 : 삭제 기능의 사용 방법 '표준 : basic_ofstream <char> 및 표준 : basic_ofstream <char> :: 연산자 = (const를 표준 : basic_ofstream <char> &)'나는 위의 코드를 실행하지만 실패

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>

+0

g ++ 버전 특정 것 같습니다. VS 2013 및 [g ++ - 5.1] (http://coliru.stacked-crooked.com/a/c83e8a3939ac3115)을 사용하여 빌드하십시오. – acraig5075

답변

3

지원 GCC 5.1에 추가 된, 그래서 당신은 GCC 4.9 함께 할 수 없습니다. 이 내용은 libstdC++ 설명서 버전 4.9에 설명되어 있습니다. https://gcc.gnu.org/onlinedocs/gcc-4.9.4/libstdc++/manual/manual/status.html#status.iso.2011

27.5 | Iostreams 기본 클래스 | 부분 | basic_ios에서 이동 및 스왑 조작이 누락되었습니다. 누락 된 io_errc 및 iostream_category. ios_base :: failure는 system_error에서 파생되지 않습니다. 누락 된 ios_base :: hexfloat.
27.6 | 스트림 버퍼 | Y |
27.7 | 포맷 및 매니퓰레이터 | 부분 | 누락 된 이동 및 스왑 조작 get_time 및 put_time 조작자가 누락되었습니다.
27.8 | 문자열 기반 스트림 | 부분 | 누락 된 이동 및 스왑 작업
27.9 | 파일 기반 스트림 | 부분 | 누락 된 이동 및 스왑 작업

GCC 5.x에서 지원되며 잘 작동하므로 잘못 입력하면 -std=c++11을 사용하는 것을 잊어 버리거나 분명히 작동하지 않는 4.9 헤더를 가리켜 야합니다.

관련 문제