I've wanted to write a program to read the extended characters from a file.

#include <iostream>
#include <fstream>

using namespace std;

int main()
 char a,ch[50]; 
 long l, m, k;
 ifstream infile;
 l = infile.tellg(); 
 infile.seekg(0, ios::end);
 m = infile.tellg();
 k = (m - l);
 infile.seekg(0, ios::beg);
 cout << ch;
 cout << endl << k;
 return 0;


The output is displayed as :


Wheras the output from the text file is :


I tried opening the file in binary format :

Now some charcters are displayed,other not!

Completely different symblos !! First i thought the console window couldn't print those charcters so i worte another program

#include <iostream>
int main()
     char a = 156;
     unsigned int b = int (a);
     std::cout << a;
     std::cout << b;
     return 0;

It prints the character perfectly in this instance.

How do i correct it ?

you opened the file in text mode, which means the operating system may translate some of those binary characters. Open the file in bianry mode (ios::binary) and your program will probably work.

Yes i tried that too but quite a few of the symbols where different.

Binary format :

Actual output :

Any other suggestions ?

It seems like your mixing the wrong data types for input and output, but I'm not sure where, Im too much a newbie, although I have had this problem for these reasons.