Write to text file - wrong character encoding?

Oct 26, 2012 at 12:48pm
closed account (DEUX92yv)
I'm trying to write to a text file, and keep getting this error message:

gedit has not been able to detect the character encoding.
Please check that you are not trying to open a binary file.
Select a character encoding from the menu and try again.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void write_maze(char *filename, char *maze, int rows, int cols)
{
	ofstream solved (filename);
	if (! solved.is_open()){
		cout << "Failed to open " << filename << endl;
	}
  solved << rows << " " << cols;
	for (int i = 0; i <= (rows * cols); i++) {
		solved << maze[i];
		if (! ((i + 1) % cols)) {
			solved << endl;
		}
	}
  solved.close();
}


What am I doing wrong? It was working earlier with a very basic file, but that didn't suit my purposes.
Last edited on Oct 26, 2012 at 12:49pm
Oct 26, 2012 at 12:50pm
Are you sure you should be using <= and not < on line 8?
Oct 26, 2012 at 12:51pm
Check the file really is text and as you think it should be with the command
cat filename
at the command line.
Oct 26, 2012 at 12:53pm
closed account (DEUX92yv)
You win, Peter. I've been changing my code so much for the last 8 hours, little details are slipping my mind. Thank you
Topic archived. No new replies allowed.