I got this silly problem and honestly dunno why it isnt working .
The scenario is i got a text file with information and i got to print the ASCII equivalent of the text into the screen .
While attempting to do so , i am getting the binary equivalent (well apparently it doesnt seem so ).
#include <iostream>
#include <fstream>
using namespace std;
int main () {
int c;
char str[10];
ifstream is;
cout << "Enter the name of an existing text file: ";
cin.get (str,10);
is.open (str); // open file
while (is.good()) // loop while extraction from file is possible
{
c = is.get(); // get character from file
cout << c ;
}
is.close(); // close file
return 0;
}
I have a test.txt file where in i have store only "d" character (without quotes)
the output got is :
1001010-1
but i want it to print it as 100
although , if i run this program i.e to find the ascii eq i get the right output .
#include<iostream.h>
using namespace std;
int main ()
{
char a = 'd';
int x = a;
cout<<x;
return 0;
}