键入 '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;
}
这是出现"没有可行的重载="错误消息的地方。如何以正确的方式转换?
在主进程中,我想将字符串加载到流中以进行标记化和进一步分析。
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
对象。 您需要从该文件对象读取。 如果fileLoadToString
是类型 juce::String
,你可以只写:
File theTextFile(myChooser.getResult());
fileLoadToString = theTextFile.readFileAsString();
如果它是不同类型的,则必须转换 readFileAsString
.
相关文章:
- cppcheck在const std::string[]上引发警告
- 将std::string传递给WriteConsole API
- 为std::string的某个索引赋值
- 使用 std::string () const 函数启动线程或未来
- 当我们进行一些操作时,应该使用什么'std::string'或'std::stringstream'?
- 如何更改大小(std::string)
- std::string 的对象真的可以移动吗?
- SegFault 同时使用 std::string::operator+= 和函数作为参数
- 无法从 std::string 中提取C++ Unicode 符号
- std::string 构造函数如何处理固定大小的 char[]?
- 真的没有来自 std::string_view 的 std::string 的显式构造函数吗?
- 将C++ std::string 转换为 UTF-16-LE 编码的字符串
- 重载 + 自己的类和 std::string 的运算符
- 如何使用 std::string 作为 QHash 的键?
- 将日语 wstring 转换为 std::string
- 可以从std::string继承以提供类型一致性吗
- 构造函数采用std::string_view与std::string并移动
- 在共享缓冲区内存中创建 ::std::string 对象
- std::string.size() 未知行为
- Valgrind 在 std::string::swap 中报告 SIGILL