【发布时间】:2018-08-22 00:28:21
【问题描述】:
我想把这个文件浏览器加载的一个txt文件的内容放到字符串'fileLoadToString'中。使用引号中的路径时,转换有效。
FileChooser myChooser ("Please select the moose you want to load...",
File::getSpecialLocation (File::userHomeDirectory),
"*.txt");
if (myChooser.browseForFileToOpen())
{
File theTextFile (myChooser.getResult());
fileLoadToString = theTextFile;
}
这里是出现“没有可行的重载 =”错误消息的地方。如何正确转换?
在主进程中,我想将字符串加载到流中以进行标记化和进一步分析。
std::ifstream inf(fileLoadToString);
任何帮助总是非常感谢,谢谢。
File FileChooser::getResult() const
{
// if you've used a multiple-file select, you should use the getResults() method
// to retrieve all the files that were chosen.
jassert (results.size() <= 1);
return results.getFirst();
}
【问题讨论】:
-
请显示
FileChooser::getResult()的定义 -
“在引用中使用路径时”是什么意思?
-
@jamesBeilby 例如当我声明一个字符串时,我可以使用 = "followedbythefilename.txt" 用文件的内容填充它
-
如果您正在使用 JUCE(猜测),您可能需要在 File 对象上调用 getFileName() 或 getFullPathName() 以获取 JUCE String 对象。然后,您需要调用 toStdString() 以获取 std::string。
标签: c++ string file stream juce