File-Binary-Mathematics

N

nguser3552

Hello everyone,

I'm wondering if someone out there knows how in a visual c++ console
application how I can do the following, and man I've tried, it seems simple
really:

I need to open up any file (the fnctl library offers hope), in binary or raw
mode just 1' and 0's whichever is preferable. Once the file is open,
attached to a stream and a buffer is created, I have to be able to take the
final object as though
it were in the following form:
object->100010101010101010....0001010
and be able to perform mathematical operations on the data. There is a great
program if you go to Google and just type in fb.c it should show up, it does
a lot of what I'm talking about, however it far to in depth for what my team
is asking of me and it is in c and uses the (argv, char**) method which
complicated things. Anyone have any idea on how to do this without creating
a Leon Tolstoy program?

Any help at this point is more than appreciated, in the afterlife I'll walk
your dog if you've any suggestions.

Thank you
(e-mail address removed)
Paul
 
B

BobR

nguser3552 wrote in message ...
Hello everyone,

I'm wondering if someone out there knows how in a visual c++ console
application how I can do the following, and man I've tried, it seems simple
really:

I need to open up any file (the fnctl library offers hope), in binary or raw
mode just 1' and 0's whichever is preferable. Once the file is open,
attached to a stream and a buffer is created, I have to be able to take the
final object as though it were in the following form:
object->100010101010101010....0001010
and be able to perform mathematical operations on the data. There is a great
program if you go to Google and just type in fb.c it should show up, it does
a lot of what I'm talking about, however it far to in depth for what my team
is asking of me and it is in c and uses the (argv, char**) method which
complicated things. Anyone have any idea on how to do this without creating
a Leon Tolstoy program?

Any help at this point is more than appreciated, in the afterlife I'll walk
your dog if you've any suggestions.
Thank you
Paul

#include <iostream>
#include <fstream>
#include <vector>
#include <bitset>

std::vector<std::string> TheFile;

void Open( char const *filename){
std::ifstream in( filename );
if(!in){ throw " Open Failed! ";} //if(!in)
for( std::string line; std::getline(in, line); ){
TheFile.push_back( line );
} // for(line)
return;
} //Open(const char*)

{ // main() or function
Open( "myfile.txt" );
std::string Bits32( TheFile.at( 0 ).substr(0, 32) );
// std::string Bits32( "00010011100010100010" ); // test
std::bitset<32> Bits( Bits32 );
std::cout << Bits << std::endl;

Bits>>=5;
std::cout<<"Bits>>=5;\n"<< Bits << std::endl;
Bits&=24;
std::cout<<"b&=24;\n"<< Bits <<std::endl;
}


std::ifstream Tfile("SomeName.txt", std::ios::binary);
.....is not what you seem to think.
 
N

nguser3552

Bob:

I've been trying to get the code you kindly sent work, but windoze is giving
me an error to the effect, "This application has requested the Runtime to
terminate it in an unusual way."

I'm not sure if its spitting this out because I'm in ms vstudio 2005 and I
need to put in the iostream using endl
statement which I'll try or if its something else. I'd toss namespace in
there but that begins to get a bit more complicated in just a console app.

I also wanted to be as concise and terse in my first posting to the group as
I could, but I probably went overboard. Here's a better understanding of how
I need to get this engineered in psuedocode.

User starts program.
Program asks user for file name (some are intl this is why I have to have
the capability of opening a .bin .txt .jen .plt)
Program uses open function with (filename, DENYNO | ios::binary, etc....
Program temporarily stores contents in a one line, no spaces
array(doubtful), buffer or vector in 1's and 0's binary format (for
mathematical reasons).

From this point I can then put the math to the file in a function and then
display the binary on the console and store the math on a floppy.

I truly appreciate the help you have provided and if you know of a way to do
the above I might stop ripping out my hair.

Thanks so much,
(e-mail address removed)
Paul

----- Original Message -----
From: "BobR" <[email protected]>
Newsgroups: comp.lang.c++
Sent: Saturday, November 25, 2006 12:31 PM
Subject: Re: File-Binary-Mathematics
 
B

BobR

nguser3552 wrote in message ...
Bob:

I've been trying to get the code you kindly sent work, but windoze is giving
me an error to the effect, "This application has requested the Runtime to
terminate it in an unusual way."

First: Please do not top-post. This is not the game-show "Jeopardy". Put your
answer below what you are replying to. Trim (remove) any old post you do not
need to make your point. Thanks.

Second: We like to see the code you tried, and the *exact* error you
received. In this case, I can guess that one of these lines caused the error:

// -------
if(!in){ throw " Open Failed! ";} //if(!in)

Change that line (if you used it) to:
( ....also #include <stdexcept> )

if( !in ){
throw std::runtime_error( " Open Failed! " );
} //if(!in)

Now your system should give more information (if that is the problem).
Do you know 'try{}/catch{}'?

// -------
std::string Bits32( TheFile.at( 0 ).substr(0, 32) );
std::bitset<32> Bits( Bits32 );

That line could fail if the input line contained any non-numeric characters.
( S/B text 1's and 0's only.)

In your program, comment out all but the file open/read in main(). Do:

std::string Bits32( TheFile.at( 0 ).substr(0, 32) );
std::cout<< Bits32 << std::endl:

Copy/paste that line here.
// -------

Trim your program down to the *smallest* that still exibits your problem, and
post that here.
( don't forget the exact error messages (just the first few) if it does not
compile.)

You can also find answers to many common problems in the FAQ:
The comp.lang.c++ FAQ is available at http://www.parashift.com/c++-faq-lite/
 
N

nguser3552

Bob:
First: Please do not top-post. This is not the game-show "Jeopardy". Put
your
answer below what you are replying to. Trim (remove) any old post you do
not
need to make your point. Thanks.

Second: We like to see the code you tried, and the *exact* error you
received.

I apologize for the poor posting manners its been awhile, I'll be more
compact and
clear. I've taken your advice and am parsing through
http://www.parashift.com/c++-faq-lite/
to learn, check compiler settings and see that all is correct before I
continue.

I will post what you requested on Mon or Tues 5th in a single message-new
slate.

Thank you for your time and reminder about posting correctly,

(e-mail address removed)

Paul...
 

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
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top