May 6, 2012 at 9:53am UTC
I compiled the following code
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
int main()
{
ifstream fin;
fin.open("file.txt",ios::binary);
ofstream fout;
fout.open("bytesequence.txt",ios::binary);
int a;
char s;
while(!fin.eof())
{
fin>>s;
fout<<s+0;
fout<<".";
}
return 0;}
the file.txt contains
abc
def
hij
the bytesequence.txt changes to
97.98.99.100.101.102.104.105.106.106.
first I'm not getting the <enter> character then i',m getting two 106's. Why's that?
May 6, 2012 at 10:32am UTC
i changed it to this...
while(fin.get(s))
{
fin.get(s);
fout.put(s+0);
fout<<".";
}
the output is
b.
.d.f.
.i.j.
some characters are missing and there not integers
Last edited on May 6, 2012 at 10:34am UTC
May 6, 2012 at 1:11pm UTC
Some characters are missing because you call get twice. Remove the second call.
The put function outputs characters. If you want integers you can output as you did before fout << s + 0;
or use a cast fout << (int ) s;
or fout << static_cast <int >(s);