vector problem???

hi guys.I need your help.My project is to read from input file some numbers then create output file.But my output file is not working.İt is always empty.In my input file, first line is rows and columns.Second line defines the magic location. If the graph has no magic location, it would be -1 -1.Third line is the grid location values

my input file
7 5
-1 -1
1 2 3 4 3
1 1 1 2 2
2 1 4 2 1
3 2 2 2 4
3 3 3 1 1
3 4 4 2 4
3 1 3 4 3





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <string>
#include<vector>
using namespace std;

int rows,cols;
int main()
{
	int first,second;
	ifstream myfile("input.txt");
	if (myfile.is_open())
	{
		myfile >>rows;
		myfile >>cols;
	}
	
	vector< vector<int> > grid(rows, vector<int>(cols));
	if (myfile.is_open())
	{
		myfile >>first;
		myfile >>second;
	}
	if (myfile.is_open())
	for(int i=0; i<rows; i++)
	{
		for (int j=0; j<cols;j++)
		{
			myfile >>grid[i][j];
		}
	}
	
	ofstream output_file ("son.txt");
	for(int i=0; i<rows; i++)
	{
		for (int j=0; j<cols;j++)
		{
			myfile>>grid[i][j];
		}
	}
	myfile.close();

	
 
return 0;
}
Last edited on
Hi, please put your code in [code][/code] tags.

One thing that I noticed is that you your ofstream object is called output_file, but you write to (and close) myfile (which is your input file).
I am sorry I forgot tags. I fixed it right now.
you are right I changed myfile word with output_file and program executes now.I can write output_file file something..thanks
Topic archived. No new replies allowed.