繁体   English   中英

如何在c ++ Visual Studios中将文本文件写入桌面?

[英]How can I write a text file to Desktop in c++ Visual Studios?

我想在向其发送该程序的任何用户计算机的桌面上创建一个文本文件。 本质上,我想弄清楚如何找到他们的桌面路径 ,以及创建一个.txt文件以填充信息以及将其放置在他们的桌面上。

首先获取到桌面的路径:

#include <windows.h>
#include <shlobj.h>
#include <string>


int main()
{
    wchar_t* pszDesktopFolderPath = NULL;
    HRESULT hr = SHGetKnownFolderPath(FOLDERID_Desktop, KF_FLAG_DONT_VERIFY, NULL, &pszDesktopFolderPath);

    if (SUCCEEDED(hr))
    {
        std::wstring strFileName(pszDesktopFolderPath);
        strFileName = strFileName + L"\\" + L"MyFileName.txt";
        CoTaskMemFree(pszDesktopFolderPath);
        pszDesktopFolderPath = NULL;
    }
    return 0;
}

然后_wfopen_s或任何其他I / O打开API(CreateFile,open等)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM