while (is.get(c)) File not opening, console hangs

I am trying to read in a file containing 0's & 1's, 64 at a time to convert into a decimal. After executing my code, cout shows no values read and my console hangs.

My code:

#include <string>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream> // std::cin, std::cout
#include <fstream> // std::ifstream

using namespace std;

int main()
{

ifstream in_file;
ofstream out_file;
string binary;
double decimal = 0;
long double std::pow(long double, int);
char c;
char str[64];

std::cout << "Enter The Filename For Input: ";
std::cin.get (str,64); // get c-string

std::ifstream is(str); // open file
// Check file is open
if (!is) {
cerr << "Can't open input file " << str << endl;
system("PAUSE");
exit(1);
}

// in_file >> is(str);

while (!is.eof()) //do while not EoF
{
while (is.get(c)) // loop getting single chars
{
if (c == '\n') { // another check for eof
cout << "The binary values read are " << is.get(c) << endl;
decimal = 0;
// in_file >> is(str); // read in NumsIn.txt
continue; // Go back to start of while loop
} // end if
decimal *= 2;
/////////////////////////////////////////////

// Convert binary to decimal

cin >> binary;

for(int counter = 0; counter < binary.size(); counter++)
if(binary.c_str()[counter] == '1')
decimal = (decimal + pow(2, counter));

cout << "The decimal representation of the given binary is: " << decimal << endl;

out_file.open("BvalueOut.txt", ios::out);
out_file << decimal; // write value to BvalueOut.txt

} // End get c

} // End EoF loop

system("PAUSE");

in_file.close();
out_file.close();

return 0;
}

Thanks in advance for any insight.
Last edited on
Topic archived. No new replies allowed.