read a text file as an array of bits / integers

A

aarthi28

Hi,
I have a text file "test.txt" that contains a series of 0's and 1's.
For example,
0000001000010100011000

I need to read these values into an array so that i can perform a
comparison with another array, and I don't know how to read the
information from the text file into an array of integers or bits.
Any help I can get is greatly appreciated.

Thanks!
 
B

BobR

Hi,
I have a text file "test.txt" that contains a series of 0's and 1's.
For example,
0000001000010100011000

I need to read these values into an array so that i can perform a
comparison with another array, and I don't know how to read the
information from the text file into an array of integers or bits.
Any help I can get is greatly appreciated.
Thanks!

{
std::string line;
std::getline( MyInFile, line );

std::vector<char> array;
for( size_t i(0); i < line.size(); ++i ){
array.push_back( line.at( i ) );
}
}

Of course, if your file is bigger than std::string.max_size(), you'll need
to do it differently. (..and there are faster ways than I have shown.)

On my win system:
std::string Astr;
cout<<"Astr.max_size() ="<<Astr.max_size()<<std::endl;
// output: Astr.max_size() =1073741820
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top