Writing to a File

Hello all,


I am writing a subroutine to write data to a text file. The function, DisplayResults takes a structure which contains the results.

All of the results are stored in a vector of tuples
It is iterated over to obtain each record.
Within each record is a vector of positions and temperatures.

I would prefer that after a single record is written, the next is written the the right of the previously written data. In other words, I would like to write across the file instead of down. Or again another way to think about it, After the inner loop completes and moves to the outer, I want the next block of data to be to the right.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void Action::DisplayResults(Action rsults)
{
	cout << "Results: " << endl;
	vector<tuple<double, double>> records;
	tuple<double, double > record;
	std::ofstream data_file;
	data_file.open("data.txt");
	int lines=0;
	for (size_t i = 0; i < rsults.results.size(); ++i)
	{
		records = rsults.results.at(i);
		for (size_t j = 0; j <records.size(); ++j)
		{
			record = records.at(j);
			data_file<<get<0>(record)<< ","<<get<1>(record); 
			data_file << endl;
			++lines;
		}
		++lines;
	}
Do you have an actual question or problem?

Do you realize that your vector records is empty and that you can't insert items into an empty vector with the .at() member function?

what do you think this does ?

data_file << endl;
Topic archived. No new replies allowed.