gpt4 book ai didi

c++ - const char* 到 TDesC16

转载 作者:行者123 更新时间:2023-11-28 08:32:22 25 4
gpt4 key购买 nike

我有一个 const char* 指定我要删除的文件。我想使用 RF::Delete 删除一个采用 TDesC16 的文件作为输入参数。有谁知道如何轻松转换

RFs fs;
TUint err;

const char *pFileToDelete = "c:\\myfile.txt";

if ( fs.Connect () == KErrNone )
{
err = fs.Delete(pFileToDelete);
fs.Close();
}

非常感谢,

最佳答案

RFs fs;
TUint err;
const char *pFileToDelete = "c:\\myfile.txt";
TPtrC8 filename8 = (const TText8*)pFileToDelete;
//ok, so we could use a TBuf or a TFileName, but we'd need to now
//the size of the TBuf at compile time and
//TFileNames should never be allocated on the stack due to their size.
//Easier to use a HBufC.
HBufC* filename = HBufC::NewLC(filename8.Length());
//Copy will only do the right thing if the text in pFiletoDelete is 7-bit ascii
filename->Des().Copy(filename8);
if ( fs.Connect () == KErrNone ){
err = fs.Delete(*filename);
fs.Close();
}
CleanupStack::PopAndDestroy(filename);

我还没有实际编译这段代码,所以它可能需要一些 TLC。

关于c++ - const char* 到 TDesC16,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1379613/

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