NewLine Creates an Equal Sign with new Line in Fstream

I am making an application that compresses CSS/HTML/JS Files by removing white space and other things but in the section that removes whitespace whenever a newline is encountered a equal sign is added.

Here is a slightly modified version of the class regarding whitespace.

Note: somethings like the test.txt instead of a variable are there for testing and debugging purposes, because I don't know how to make Visual Studio use the txt file inside the debugging directory during debugging

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
string minimize::open(/*char &file*/)
{
	//Open File
	fstream code ("new.txt", fstream::in | fstream::out);

	//Alocate Memory
	int length = 0;

	//Get Length of File
	code.seekg (0, ios::end);
    length = code.tellg();

	//Move Buffer back to beggining of file for opperations
	code.seekg (0, ios::beg); 

	//Allocate Memory
	char* content = new char [length];

	//Move content to array if buffer is still available
	if (code.good())
	{
		code.read(content,length);
	}
	else
	{
		cout << "Failure";
	}

	/*Move Content From Memory to Local Variables
	Then Close The File*/
	code.write(content, length);
	code.close();
	string pre_process;
	cout << pre_process;
	for (int i = 0; i < length; i++)
	{
		pre_process += content [i];
 	}
 
	//Free Memory
	delete content;
 
	return pre_process;
	
}

ouput when given hi followed by a new line is

1
2
hi
=



I am Using Visual Studio 2012 RC. Please Help me please i recently finished Accelerated C++ so I know most of the STL (they skipped alot of information on fstream).

Thanks Ahead of time
Last edited on
Try open the file in binary mode.
Ty it worked
Topic archived. No new replies allowed.