输入 'File' 到 'std::string'
Type 'File' to Type 'std::string'
我想将此文件浏览器加载的一个 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
returns 一个 juce::File
对象。您需要从该文件对象中读取。如果 fileLoadToString
是 juce::String
类型,你可以这样写:
File theTextFile(myChooser.getResult());
fileLoadToString = theTextFile.readFileAsString();
如果是不同的类型,你将不得不转换readFileAsString
的结果。
我想将此文件浏览器加载的一个 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
returns 一个 juce::File
对象。您需要从该文件对象中读取。如果 fileLoadToString
是 juce::String
类型,你可以这样写:
File theTextFile(myChooser.getResult());
fileLoadToString = theTextFile.readFileAsString();
如果是不同的类型,你将不得不转换readFileAsString
的结果。