By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,613 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,613 IT Pros & Developers. It's quick & easy.

read a text file as an array of bits / integers

P: n/a
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!

Jun 12 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a

<aa******@gmail.comwrote in message...
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<chararray;
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

--
Bob R
POVrookie
Jun 12 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.