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());
精彩评论