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

开发者 https://www.devze.com 2023-04-06 22:52 出处:网络
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 concaten
 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

精彩评论

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