繁体   English   中英

在结构中使用fstream,出现错误

[英]Using fstream in struct, errors

我正在尝试在结构内部初始化文件输出流。 我应该在主函数中定义的名称应该创建的文件,即:

#include <iostream>
#include <fstream>

struct str {
std::ofstream fs;

};

int main() {
    str G;
    G.fs("hello.txt",std::ios::app);
}

这给了我:错误:调用'(std :: fstream {aka std :: basic_fstream})(const char [10],const openmode&)'|没有匹配项

怎么做对?

初始化构造函数不能以这种方式使用。 尝试这个:

int main() {
    str G;
    G.fs.open("hello.txt",std::ios::app);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM