gpt4 book ai didi

c++ - 将std::basic_string 转换为字符串

转载 作者:行者123 更新时间:2023-12-01 14:53:50 46 4
gpt4 key购买 nike

虽然MediaInfoDLL以std::basic_string<Char>格式返回元数据(采样率, channel ,流大小,标题...),但我需要转换为字符串以便以后进行处理。例如,mi.Get(Stream_Audio, 0, __T("Performer"))std::basic_string<Char>格式返回“艺术家名称”。

你能帮助我吗?

先感谢您

最佳答案

通过阅读MediaInfoLib library's C++代码,似乎有两种可能性。该库定义了一个类型别名String,这就是您所看到的类型。

首先,CharString类型的here is the definition:

namespace MediaInfoLib {

/* ... */

//Char types
#undef __T
#define __T(__x) __T(__x)
#if defined(UNICODE) || defined (_UNICODE)
typedef wchar_t Char; ///< Unicode/Ansi independant char
#undef __T
#define __T(__x) L ## __x
#else
typedef char Char; ///< Unicode/Ansi independant char
#undef __T
#define __T(__x) __x
#endif

typedef std::basic_string<MediaInfoLib::Char> String; ///< Unicode/Ansi independant string

/* ... */

} // end namespace

如果在构建库时定义了 UNICODE_UNICODE宏,则类型为 std::basic_string<wchar_t>,即 std::wstring in the standard library

要将其转换为 std::string,请参见以下问题:
How to convert wstring into string?

simplest answer there使用 std::wstring_convert

如果在构建库时未定义宏 UNICODE_UNICODE,则 MediaInfoLib::Charchar类型,而 MediaInfoLib::String类型是 std::basic_string<char>已经是 std::string。也就是说,在这种情况下,返回类型已经是std::string。

关于c++ - 将std::basic_string <Char>转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59603127/

46 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com