Read all values /strings form unknown file

Hi guys,

I'm having a little problem:
For an assignment I have to write a program which basically converts 8 bit binary numbers to ASCII and outputs the assembled text. Here's the catch:

The 8-bit binary numbers are provided by some external file (which only contains 8 bit binary numbers); the name and hence length is not known. The external file is called with a pointer upon execution
(./"conversion program" < external_file.in).

I'm getting the 8 bits as a string, calculate/convert decimals, output char type. HOW do I know when to stop the loop? If I just pick an insanely high number I get random stuff at the end; no boundaries obviousely lead to an infinite loop.
Can I determine the lenght of this random ext file somehow nonetheless?
Is it possible to create a vector which dinamically adjusts itself until there are no more strings = end of the file?

Any ideas? Thanks in advance.
anndurill
1
2
3
4
5
6
7
std::vector< std::string > seq ;

std::ifstream file( "external_file.in" ) ;
std::string bits ;
while( file >> bits ) seq.push_back(bits) ;

std::cout << seq.size() << " strings were read\n" ;
I'll restate the problem: I don't know the external file. It could be named newspaper.in or protestor_sign.in or anything else...I only know they'll all contain nothing but binary numbers
1
2
3
4
5
6
7
8
9
10
11
std::vector< std::string > seq ;

std::string name_of_external_file ;
std::cout << "name of external file? " ;
std::cin >> name_of_external_file ;

std::ifstream file( name_of_external_file /* .c_str() */ ) ; 
std::string bits ;
while( file >> bits ) seq.push_back(bits) ;

std::cout << seq.size() << " strings were read\n" ;
I have to write a program which basically converts 8 bit binary numbers to ASCII and outputs the assembled text.

What format does "8 bit binary numbers" mean? Are these ASCII text of '0' and '1'? Or is it raw binary bytes?

the name and hence length is not known.
So read until end of file is reached. Am I missing something?
@pheininger: the thing is, the way I solved it is with a loop which needs a value to know when to stop.
I think I'll just go for JLBorges idea...

Thanks to both of you!
He's a great guy. :)
Topic archived. No new replies allowed.