[英]Properly Saving to file with a file name
ofstream myfile;
string s=r->str_name+".txt";
myfile.open (s);
其中r-> str_name是字符串。 如果r-> str_name是“ animals”,如果我将其连接起来,是否会将文件另存为animals.txt?
关。 它确实如您期望的那样在r->str_name
将是“ r->str_name
”,但要将其传递到myfile.open()
您必须将其转换为const char*
如下所示:
myfile.open (s.c_str());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.