gpt4 book ai didi

c++ - 键入 'File' 到键入 'std::string'

转载 作者:行者123 更新时间:2023-11-27 22:40:38 26 4
gpt4 key购买 nike

我想将此文件浏览器加载的 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;

}

这是出现“No viable overloaded =”错误消息的地方。如何以正确的方式转换?

在主进程中,我想将字符串加载到流中以进行标记化和进一步分析。

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();
}

最佳答案

myChooser.getResult 返回一个 juce::File 对象。您需要从该文件对象中读取。如果 fileLoadToStringjuce::String 类型,你可以这样写:

            File theTextFile(myChooser.getResult());
fileLoadToString = theTextFile.readFileAsString();

如果是不同的类型,你将不得不转换readFileAsString的结果。

关于c++ - 键入 'File' 到键入 'std::string',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49261430/

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