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;
 infile.open("as6.txt");
 l = infile.tellg(); 
 infile.seekg(0, ios::end);
 m = infile.tellg();
 k = (m - l);
 infile.seekg(0, ios::beg);
 
 while(infile!=0)
 {
 infile.get(ch,50);
 cout << ch;
 }
 infile.close();
 
 cout << endl << k;
 
 cin.get();
 return 0;

}

The output is displayed as :

┼╜:♀╤ô1∞↑∩▬Zσô*▓ws┐Q
49

Wheras the output from the text file is :

Ž:Ñ“1ìïZå“*²ws¿Qœu!¥¶T›ö–ŽFŠsÙJr¯f¥åðXîRÇ?ù

I tried opening the file in binary format :
┼╜:♀╤ô1∞↑∩▬Zσô*▓ws┐Q→£u!Ñ╢T¢÷ûÄFès┘Jr»fÑ≡XεR╟?∙

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;
     std::cin.get();
     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 :
┼╜:♀╤ô1∞↑∩▬Zσô*▓ws┐Q→£u!Ñ╢T¢÷ûÄFès┘Jr»fÑ≡XεR╟?∙

Actual output :
Ž:Ñ“1ìïZå“*²ws¿Qœu!¥¶T›ö–ŽFŠsÙJr¯f¥åðXîRÇ?ù

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.