[英]implicit instantiation of undefined template: basic_fstream<string>
我正在使用 clang/llvm 8.0.0 在 macOS 上編譯它。 為 C++14 編譯。
#include <fstream>
#include <string>
using namespace std;
basic_fstream<string> open_file(string file);
int main()
{
basic_fstream<string> f = open_file("test");
f.close();
}
basic_fstream<string> open_file(string file) {
basic_fstream<string> f;
f.open(file);
if(!f.is_open()) {
f.clear();
f.open(file, ios_base::out);
f.close();
f.open(file);
}
return f;
}
它產生一個很長的錯誤列表,但第一個是:
implicit instantiation of undefined template 'std::__1::codecvt<std::__1::basic_string<char>, char, __mbstate_t>'
__always_noconv_ = __cv_->always_noconv();
basic_fstream
的模板參數是字符類型,而不是字符串類型。 例如,C++ 實現支持的典型字符類型是basic_fstream<char>
和basic_fstream<wchar_t>
。
但是為什么要使用這個模板呢? 只需使用std::fstream
,又名std::basic_fstream<char>
; 或std::wfstream
,又名std::basic_fstream<wchar_t>
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.