const unsigned char * to std :: string [英] const unsigned char * to std::string

查看:1419
本文介绍了const unsigned char * to std :: string的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

sqlite3_column_text返回一个const unsigned char *,我如何将它转换为std :: string?我试过std :: string(),但我得到一个错误。

sqlite3_column_text returns a const unsigned char*, how do I convert this to a std::string? I've tried std::string(), but I get an error.

代码:

temp_doc.uuid = std::string(sqlite3_column_text(this->stmts.read_documents, 0));

错误:

1>.\storage_manager.cpp(109) : error C2440: '<function-style-cast>' : cannot convert from 'const unsigned char *' to 'std::string'
1>        No constructor could take the source type, or constructor overload resolution was ambiguous


推荐答案

您可以尝试:

temp_doc.uuid = std::string(reinterpret_cast<const char*>(
      sqlite3_column_text(this->stmts.read_documents, 0)
  ));

std :: string 构造函数 const unsigned char * ,显然它不会。

While std::string could have a constructor that takes const unsigned char*, apparently it does not.

您可以查看这个有些相关的问题:为什么do C ++ streams使用char而不是unsigned char?

Why not, then? You could have a look at this somewhat related question: Why do C++ streams use char instead of unsigned char?

这篇关于const unsigned char * to std :: string的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆