gpt4 book ai didi

c++ - 如何在 C++ 中读取不包含在 ascii 中的字符?

转载 作者:太空狗 更新时间:2023-10-29 20:56:06 25 4
gpt4 key购买 nike

我正在浏览编辑标题的文件文件夹。我试图删除标题的某个部分,但标题中用于分隔的括号不是标准的 ascii,所以我想不出删除它的方法。这是标题的示例:【删除此部分】保留此部分。我已经包含了我正在使用的编码。我使用 cstring 来存储标题,然后使用 cstring::find() 来定位该部分,但它无法定位该类型的括号。

    //sets definition
HANDLE hfind;
WIN32_FIND_DATA data;

//creates string for to search for a specific file
CString FileFormat = FolderPath + Format;
CString NewTitle, PulledFile;

//sets definition for retrieving first file
hfind = FindFirstFile(FileFormat, &data);

//runs loop if handle is good
if (hfind != INVALID_HANDLE_VALUE)
{
//loops until it hits the end of the folder
do {
//adds filename to vector
PulledFile = data.cFileName;
if(PulledFile.Find(L'【') != -1)
{
while (PulledFile.Find(L'】') != -1)
{
PulledFile = PulledFile.Right(PulledFile.GetLength() - 1);
}
}
NewTitle = PulledFile.Left(PulledFile.GetLength()-(Format.GetLength() + 9));
if (sizeof(NewTitle) != NULL)
{
v.push_back(NewTitle);
}
} while (FindNextFile(hfind, &data));
}

最佳答案

您面临的最有可能的问题是您没有正确编译。根据CString documentation :

A CStringW object contains thewchar_t type and supports Unicode strings. A CStringA object contains the char type, and supports single-byte and multi-byte (MBCS) strings. A CString object supports either the char type or the wchar_t type, depending on whether the MBCS symbol or the UNICODE symbol is defined at compile time.

实际的底层类型取决于你的编译参数。最有可能发生的情况是,它正在尝试将 Unicode 字符串与您的 MBCS 字符串文字值进行比较,但没有返回任何内容。

如果您想解决这个问题,您应该决定是使用 Unicode 还是 MBCS,并相应地更新您的编译参数,定义 MBCSUNICODE

如果您使用 Unicode,则必须更改您的字符串文字,因为它目前适用于 MBCS。您可以使用代码点 L'\u3010' 来返回正确的字符,或者确保您的文件使用 Unicode 编码并使用 u'【'

关于c++ - 如何在 C++ 中读取不包含在 ascii 中的字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34388092/

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