将std :: strings转换为WCHAR *和char *

时间:2015-11-06 03:17:50

标签: c++ string char type-conversion filepath

我正在尝试创建一个资源管理器,告诉您文件基于关键字的位置。我试图将它实现到我的Directx11编程代码中,但我遇到了一些问题。该代码需要WCHAR*char*个文件路径。我有以std :: string格式编写的文件路径。

char* ResourceManager::getFilePathCHAR(string reference){
    string location;
    //looks through a file and gives the folder
    location = parser(reference);
    string result;
    //adds the other stuff like c:// ........../image.png
    result = appender(location, reference);
    m_filePathChar = new char[result.length() + 1]; ////--|
    strcpy(m_filePathChar, result.c_str());         ////--|-> part im looking at
    return m_filePathChar;                          ////--|
}

这个问题是我读过的其他信息告诉我这样的返回指针很糟糕,所以我只想知道是否有更好的方法来做到这一点?另外,我如何将std::string转换为WCHAR*。我可能看起来不够努力,但我检查过的大多数地方都给了我wchar_t的信息。我仍然是相对较新的指针,所以我不确定你能做什么和不能做什么的确切规则。感谢您的帮助和意见。

0 个答案:

没有答案
相关问题