我不认为我已经掌握了shared_ptr
。
示例代码:
shared_ptr<ofstream> logger;
int main(){
logger = make_shared<ofstream>(new ofstream("ttt.txt"));
*logger <<"s";
return 0;
}
错误 1 错误 C2664: 'std::basic_ofstream<_Elem,_Traits>::basic_ofstream(const char *,std::ios_base::openmode,int)' : 无法从 'std::basic_ofstream<_Elem,_Traits> 转换参数 1 ' 到 'const char *' c:\program files (x86)\microsoft visual studio 10.0\vc\include\xxshared 13
编辑:
[
In the mean time, if I wanna close the ofstream while some crashes happened.
How can I do it?
I mean if shared_ptr release the memory without closing the file.
There would be problems.
]
我不知道如何做到这一点。或者,也许这根本就是胡说八道。希望任何人都可以提出想法或指出我对shared_ptr
.