DOS output different from file

I wrote a program to convert a string of 0 and 1's to char and write to a file and then read back from the file and output the corresponding string. It works fine but when I cout << the character read from the file, it looks different at the DOS prompt.
Here's the code:
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
int stringtoInt( string s)
{
	unsigned int k = 0;
	unsigned int  p = 128;
	for (int i = 0; i <s.length(); i++)
	{
		string s2 = s.substr(i,1);
		if (s2.compare("1") == 0) //true, bit should be 1
		{k = k | p;}
		p = p/2;
		
	}
	return k;
}

void chartobitString( unsigned char c)
{
	string s;
	unsigned int i = (unsigned int) c; 
	unsigned int p = 128;
	for (int k = 0; k <8; k++)
	{
		if ((i & p) == p)
		{
			string s2 = "1";
			s.append(s2);
		}
		else
		{
			string s2 = "0";
			s.append(s2);
		}
		p = p/2;
	}
	cout << s <<endl;
}

int main (){
string s2 = "11010101";
	cout<< (unsigned char) stringtoInt(s2) <<endl;
	ofstream myfile;
	myfile.open("output.txt");
	if (myfile.is_open())
	{
		unsigned char c = ( unsigned char) stringtoInt(s2);
		myfile << c;	
	 }
	  myfile.close();


	 ifstream myfile1;
	 myfile1.open("output.txt");
	 if (myfile1.is_open())
	{
		while (!myfile1.eof())
			{
				unsigned char aa1 = myfile1.get();
				cout<< aa1 <<endl; //this is different from the //file character !
				chartobitString(aa1);
			}
	  
	 }
	 myfile1.close();
return 0;

}
Topic archived. No new replies allowed.