如何在c ++中重用字符串变量 [英] How to reuse a string variable in c++

查看:131
本文介绍了如何在c ++中重用字符串变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是正确的,它工作正常

Is this correct, it works OK

string str("in.dat");
ifstream fin(str.c_str(), ios::binary | ios::ate );
.
.
.
//Do I need to clear the string before assigning new name???
str = "out.dat";
ofstream fout(str.c_str(), ios::binary); //seems to work


$ b $ p

Regards

推荐答案

其他人都说的是真的。但是,在你发布的代码中,你可以这么说:

What everyone else has said is true. However, in the code you posted you could just as well have said:

ifstream fin( "in.dat", ios::binary | ios::ate );
ofstream fout( "out.dat", ios::binary );

这篇关于如何在c ++中重用字符串变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆