Binary to Dec Source Code
Code:
#include <iostream>
#include <fstream>
#include <conio.h>
#include <stdlib.h>
using namespace std;
class binAndDec
{
public:
int loadFromFile(char File[10]);
void binToDec();
char textString[6];
char Copy[6];
int n;
};
int binAndDec::loadFromFile(char File[10])
{
char text;
ifstream tFile(File);
tFile.get(textString);
tFile.close();
if(textString==0)
{
cout << "NULL File!" << endl;
return 1;
}
return 0;
}
void binAndDec::binToDec()
{
for(int tmp=0;tmp<6;tmp++)
{
Copy[tmp]=textString[tmp];
}
n=0;
for (int x=0; Copy[x] != '\0' && (Copy[x] == '1' || Copy[x] == '0'); x++)
{
n <<= 1;
if (Copy[x]== '1')
{
n += 1;
}
}
}
int main()
{
binAndDec mains;
if(mains.loadFromFile("text.txt")==1)
{
return 1;
}
else
{
mains.binToDec();
cout << (char)mains.n << endl;
}
getch();
return 0;
}
My question is what's wrong when I use the get function? I'm going to set it up to load more than one string of binary. Any ideas?