VS 2017 C++编译器在 VS 2005 中找不到匹配函数
VS 2017 C++ compiler cannot find matching function was OK in VS 2005
我正在得到
">错误 C3861:"to8Bit":找不到标识符"在此情况下:
typedef struct _ustruct2
{
int which;
union
{
double d;
tstring * s;
bool b;
char e;
} uu;
} ustruct2;
std::string to8Bit(const std::string &s);
std::string to8Bit(const std::string s);
std::string to8Bit(const tstring s);
std::string to8Bit(tstring s);
std::string to8Bit(tstring &s);
std::string to8Bit(wchar_t * pc);
std::string to8Bit(const tstring &s);
std::string to8Bit(const char * pc, int len = -1);
std::string to8Bit(const wchar_t * pc, int len = -1);
static void outputustruct(FILE * opmte, int i, const char * s, const ustruct2 &u)
{
std::string mys2 = to8Bit((*u.uu.s).c_str());
}
还有一些其他版本的to8BIT
我认为这篇文章不需要。 但我认为其中一个会匹配。 我尝试去掉函数输出结构函数标题中的常量和/或与号,并在删除与号时删除to8Bit
调用中的星号。 我已经尝试了结构定义中的字符串和 tstring 以及带有错误的代码,但我所做的一切都无法编译。
此代码在VS 2005中工作正常,但在VS 2017中无效。 根据我的经验,MS 在更高版本中收紧编译器以更严格地符合标准,但我看不出是什么导致了这里的编译器错误。
C++11std::wstring_convert
(在 C++17 中已弃用(提供了一个简单的解决方案:
在您的情况下,字符串定义为:
#include <tchar.h> // For _TCHAR
typedef std::basic_string<_TCHAR> tstring;
可以像这样转换:
#include <locale>
#include <codecvt>
int main()
{
tstring string_to_convert = L"Follow the white rabbit";
// Converter setup:
using convert_type = std::codecvt_utf8<wchar_t>;
std::wstring_convert<convert_type, wchar_t> converter;
// Convert (.to_bytes: wstr->str, .from_bytes: str->wstr)
std::string converted_str = converter.to_bytes(string_to_convert);
return 0;
}
或者在您的情况下,如下所示:
#include <locale>
#include <codecvt>
static void outputustruct(FILE * opmte, int i, const char * s, const ustruct2 &u)
{
// Converter setup:
using convert_type = std::codecvt_utf8<wchar_t>;
std::wstring_convert<convert_type, wchar_t> converter;
// Convert:
string mys2 = converter.to_bytes(*u.uu.s);
}
(这适用于VS2017 C++(
相关文章:
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 为什么野牛仍在使用"int yylex(void)",却找不到"int yylex(YYS
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 找不到QtResource文件中的文件
- VC++本机单元测试,找不到调试符号
- RegGetValue在当前用户下找不到名称
- 带有 -stdlib=libc++ 的 clang++ 9.0.1 找不到<optional>
- c++找不到具有相同哈希的无序集合元素
- 找不到以下加速库:boost_fiber
- 找不到 FLTK(缺少:FLTK_INCLUDE_DIR)
- 设置 Visual Studio for MPI: 找不到标识符错误
- VS 2017 C++编译器在 VS 2005 中找不到匹配函数
- 构建在VS 2013中找不到平台工具集= 'v141'
- VS 2017 构建工具失败,出现错误 MSB4019:找不到导入的项目"D:Microsoft.Cpp.Default.props"
- 使用 Cmake 编译 LZO 时,它注意到找不到任何 VS 实例
- VS 2017 找不到 DirectX 包含文件
- windbg 和 VS 找不到我的 pdb 文件
- Qt-vs-addin找不到vs2015的安装