const char* 到 TDeC16
我有一个 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();
}
非常感谢,
I have a const char* that specifies the file that I want to delete.
I want to use RF::Delete to delete a file which takes a TDesC16
as input argument. Does anyone know how to easily convert
RFs fs;
TUint err;
const char *pFileToDelete = "c:\\myfile.txt";
if ( fs.Connect () == KErrNone )
{
err = fs.Delete(pFileToDelete);
fs.Close();
}
Many thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我实际上还没有编译这段代码,所以它可能需要一些 TLC。
I haven't actually compiled this code so it may need som TLC.
类似的事情:
但请检查 http://descriptors.blogspot.com
Something along these lines:
but check http://descriptors.blogspot.com
取决于字符串
pFileToDelete
的字符编码。如果您不知道,那么您需要找出(或自己定义)。假设它是 7 位 ASCII,那么
大括号就在那里,因为 TFileName 是一个相当大的类(512 字节左右,IIRC),因此您在将一个放入堆栈时要稍微小心,并给它尽可能小的范围。您可以改为堆分配。
如果是 UTF-8,则还有更多工作要做,请查看
CnvUtfConverter
类中的ConvertToUnicodeFromUTF8
。如果可以的话,通常最好首先将文件名定义为描述符文字。
Depends what the character encoding is of the string
pFileToDelete
. If you don't know, then you need to find out (or define it yourself).Assuming that it's 7-bit ASCII, then
Braces are there just because TFileName is quite a large class (512 bytes or so, IIRC), so you want to be slightly wary about putting one on the stack, and give it the smallest scope possible. You could heap-allocate instead.
If it's UTF-8, then there is more work to do, check out
ConvertToUnicodeFromUTF8
in classCnvUtfConverter
.It's usually better to define your filename as a descriptor literal in the first place, if you can.