sqlite3_open返回14
如果路径中含有中文,open的时候会返回14,需要将全路径名转换为UTF8编码
#include <codecvt>
//将GBK编码的字符串转换为UTF8
string toUtf(const string &gb2312)
{
#ifdef _MSC_VER
const static locale loc("zh-CN");
#else
const static locale loc("zh_CN.GB18030");
#endif
vector<wchar_t> wstr(gb2312.size());
wchar_t* wstrEnd = nullptr;
const char* gbEnd = nullptr;
mbstate_t state = {};
int res = use_facet<codecvt<wchar_t, char, mbstate_t> >
(loc).in(state,
gb2312.data(), gb2312.data() + gb2312.size(), gbEnd,
wstr.data(), wstr.data() + wstr.size(), wstrEnd);
if (codecvt_base::ok == res)
{
wstring_convert<codecvt_utf8<wchar_t>> cutf8;
return cutf8.to_bytes(wstring(wstr.data(), wstrEnd));
}
return string();
}