C++ How to create a function writing data in file for multiple use with different names -


i have data in array manipulated in 5 or 6 steps. after each step want program write file manipulated data. working code that:

ofstream mirroreddata("mirroreddata.dat", ios::out);    (int = 0; < n_values; i++) {     mirroreddata << datavector[i] << "\n";      } mirroreddata << endl;                                   mirroreddata.close();     

the problem is, don't want write thing multiple times. want create function have call name of file (here: mirroreddata) , n_values , datavector. giving function datavector , n_values no problem, how tell writing data in new file? code fragment not right:

void createdataoutputfile(int n_values, double* datavector) {     ofstream mirroreddata("mirroreddata.dat", ios::out);                                                         (int = 0; < n_values; i++)     {         mirroreddata << datavector[i] << "\n";           }     mirroreddata << endl;                                } 

so how call writing data in new file (for example smoothed data in file "smoothed")?

thanks answers

easy: add parameter filename:

#include <string>  void createdataoutputfile(int n_values, double* datavector, const std::string& fname) {     ofstream mirroreddata(fname, ios::out);                                                         (int = 0; < n_values; i++)     {         mirroreddata << datavector[i] << "\n";           }     mirroreddata << endl;                                } 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -