str_name is a string.If r->str_name was \"animals\" , would it 开发者_开发技巧save the file as animals.txt if i concaten" />
开发者

Properly Saving to file with a file name

 ofstream myfile;
    string s=r->str_name+".txt";
    myfile.open (s);

where r->str_name is a string. If r->str_name was "animals" , would it 开发者_开发技巧save the file as animals.txt if i concatenate like this?


Close. It does do as you expect in that r->str_name will be "animals.txt" but to pass it to myfile.open() you have to turn it into a const char* like so:

myfile.open (s.c_str());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜