Hi, I'm quite a beginner and not sure if I can be helpful in the future. But I'll try!
anyway, here is my problem...
I've been searching on the net & looking up books but still don't have a clue of how to get it work.

I have to simulate a Physics problem.
The task is to investigate how the system differs from temperature.
But the simulation was done at each constant temp,
such that I need to output the data from each simulation to Excel and compare by plotting graphs.
the following is the simplified version of my code (there were too many calculations)
this clearly just overwrite everything when I change the temperature!
I really need some help!

#include <iostream>
#include <fstream> 
#include <cmath>
using namespace std;

int main (void){

	double T=10;  //start from temp=10, up to temp=100

	for (T=10; T<=100; T+=10){

    //Want to assign the value of T to the BOLD part of the  file name
		ofstream outfile("results.xls_[B]temperature[/B].xls");
		outfile << "loop \t E \t average"<<endl;
		double E=0,average=0;			
                              //set initial conditions at T

		for (int i=1; i<1001; i++){
		E += 1*T;
		average = E/T;
		outfile << i <<"\t"<< E <<"\t"<< average <<endl;
9 Years
Discussion Span
Last Post by Salem

Use a string stream to create a filename, like so.

#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;

int main()
    ostringstream fname;
    int        T = 22;
    fname << "results.xls_" << T << ".xls";
    cout << fname.str() << endl;
    ofstream outfile(fname.str().c_str());
    return 0;
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.