- 我已经写了一个补丁来写文件和它的工作
//To write a file from this location
std::ofstream myfile;
myfile.open("warn_sen.txt");
myfile << "IT HITS HERE = " "n";
myfile.close();
- 但是读操作失败,说明没有转换支持。
//To read a file from this location std::ifstream evadefile; evadefile.open("evade_sen.txt"); string flag_01 = evadefile; evadefile.close();
ERROR - E0312没有合适的用户定义转换"std::ifstream";std:: string"存在
请同样帮助我,非常感谢。
如果您想将整个文件读取为字符串,您可以执行以下操作:
std::ifstream evadefile;
evadefile.open("evade_sen.txt");
string flag_01(std::istreambuf_iterator<char>{evadefile}, {}); // in header <iterator>
evadefile.close(); // By the way, you can also omit this line if you are going to work only with this file using the ifstream, because of RAII