문제
이 코드 사용 :
#include <fstream>
#include <boost/archive/text_oarchive.hpp>
using namespace std;
int main()
{
std::ofstream ofs("c:\test");
boost::archive::text_oarchive oa(ofs);
}
Boost Archive 라인을 실행할 때 런타임에서 처리되지 않은 예외를 얻고 있습니다.
boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::archive::archive_exception> >
해결책
다음 줄은 오류가 있습니다.
std::ofstream ofs("c:\test");
파일이 호출 된 경우 컴파일러가 경고를 뱉었을 것입니다. jest
; 하지만 '\t'
- 탭을 삽입하기위한 탈출이되면 오류는 잡히지 않습니다. 요컨대, 파일이 생성되지 않습니다. 다음과 같이 테스트 할 수 있습니다.
if (ofs.good()) { ... }
이제 파일이 생성되지 않았으므로 유효한 반복자가 없습니다. boost::archive::text_oarchive
예외가 발생합니다.
이 시도:
std::ofstream ofs("c:\\test");
// --^ (note the extra backslash)
if (ofs.good()) {
boost::archive::text_oarchive oa(ofs);
// ...
}
도움이 되었기를 바랍니다!
추신: 내가 당신이 사용하려고한다면 내가 스스로를 막을 수 없었던 마지막 nit
using namespace std;
그 다음에
ofstream ofs("c:\\test");
충분합니다. 물론 자격을 갖춘 오류가 아닙니다. ofstream
, 그러나 그것은 최고의 코딩 스타일이 아닙니다. 그러나 당신은 사용한다는 것을 알고 있습니다 using namespace
나쁘지 않습니까?
pps:고맙습니다 -- sharptooth
그것을 상기시켜주기 위해 \t
당신에게 탭을 얻습니다!
다른 팁
근본 원인이 무엇인지 확인하려면 예외를 포착 한 다음 Exception_code를 검사해야합니다.
제휴하지 않습니다 StackOverflow