I am having trouble giving the user the option to name the output file (using Dev-C++) and then writing to that particular output file. Here is my code thus far (note-some of the stuff I have in there is incomplete, I know):
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cmath>
usingnamespace std;
constdouble e=2.71828183;
constdouble c1=374200000, c2=14390;
double E, frac;
double wave_start, wave_final;
double wave_inc, temp;
double test;
void info_block();
void file_print();
void file_print_clean();
int main ()
{
cout<<"Please enter a starting value for the wavelength range: ";
cin>>wave_start;
cout<<"Please enter an ending value for the wavelength range: ";
cin>>wave_final;
cout<<"Please enter a value for the wavelength increment: ";
cin>>wave_inc;
cout<<"Please enter a value for temperature in Kelvin: ";
cin>>temp;
string filename;
ofstream outfile;
cout<<"What is the name of the output file? (be sure to include extension)";
cin>>filename;
outfile.open(filename.c_str());
info_block();
for (wave_start; wave_final>=wave_start; wave_start=wave_start+wave_inc)
{
frac=(c2/(wave_start*temp));
E=c1/((pow(wave_start,5))*((pow(e,frac))-1));
cout<<"\t\t "<<wave_start<<"\t\t "<<E<<endl;
filename.c_str()<<"\t\t "<<wave_start<<"\t\t "<<E<<endl;
}
system("pause");
return(0);
}
void info_block()
{
cout<<"\n\t\t Energy report for T = "<<temp<<endl;
cout<<"\n\t\t Wavelength";
cout<<"\t\t E "<<endl;
cout<<"\t\t ---------- \t\t ---"<<endl;
}
void file_print()
{
}
That's where I'm trying to write to the outfile. The error I'm getting is:
invalid operands of types `const char*' and `const char[7]' to binary `operator<<'
What am I doing wrong here? Any help would be appreciated! If I need to go about naming the outfile in a completely different method, just let me know. I am open to any and all help/changes. Thanks!
Also, is it possible to create more than one outfile for one program? Basically I need one version with the void info_block() in the outfile and one without it. I need the one without it so I can import it into MATLAB.
Alright I'll give that a try. Like I said before, I'm trying to print one outfile with the info_block header and one without. As the program stands right now, it's making one outfile without the info_block header. Im fiddling around with it trying to get it to print the info_block header to the outfile, but I cant seem to get it to work. How would I go about this?