473,320 Members | 1,580 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

File-Binary-Mathematics

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
pa*******@comcast.net
Paul
Nov 25 '06 #1
4 1886

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::stringTheFile;

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<32Bits( 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.

--
Bob R
POVrookie
Nov 25 '06 #2
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,
pa*******@comcast.net
Paul

----- Original Message -----
From: "BobR" <Re***********@worldnet.att.net>
Newsgroups: comp.lang.c++
Sent: Saturday, November 25, 2006 12:31 PM
Subject: Re: File-Binary-Mathematics

>
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::stringTheFile;

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<32Bits( 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.

--
Bob R
POVrookie
"BobR" <Re***********@worldnet.att.netwrote in message
news:qS*********************@bgtnsc04-news.ops.worldnet.att.net...
>
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::stringTheFile;

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<32Bits( 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.

--
Bob R
POVrookie


Nov 27 '06 #3

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<32Bits( 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/

--
Bob R
POVrookie
Nov 27 '06 #4
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,

pa*******@comcast.net

Paul...
Dec 3 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
18
by: Dino | last post by:
dear all, i've created an application for a customer where the customer can upload ..csv-files into a specified ftp-directory. on the server, a php-script, triggered by a cronjob, reads all the...
3
by: Pernell Williams | last post by:
Hi all: I am new to Python, and this is my first post (and it won't be my last!), so HELLO EVERYONE!! I am attempting to use "xreadlines", an outer loop and an inner loop in conjunction with...
7
by: Joseph | last post by:
Hi, I'm having bit of questions on recursive pointer. I have following code that supports upto 8K files but when i do a file like 12K i get a segment fault. I Know it is in this line of code. ...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
0
by: troutbum | last post by:
I am experiencing problems when one user has a document open through a share pointing to the web site. I use the dsolefile to read the contents of a particular directory and then display them in a...
1
by: Mika M | last post by:
I have made Setup and Deployment Project for my application. This application uses couble of Crysral Report .rpt -files, so I included following into Setup and Deployment Project ... -...
0
by: thjwong | last post by:
I'm using WinXP with Microsoft Visual C++ .NET 69462-006-3405781-18776, Microsoft Development Environment 2003 Version 7.1.3088, Microsoft .NET Framework 1.1 Version 1.1.4322 SP1 Most developers...
17
by: Peter Duniho | last post by:
I searched using Google, on the web and in the newsgroups, and found nothing on this topic. Hopefully that means I just don't understand what I'm supposed to be doing here. :) The problem: ...
2
by: Derik | last post by:
I've got a XML file I read using a file_get_contents and turn into a simpleXML node every time index.php loads. I suspect this is causing a noticeable lag in my page-execution time. (Or the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.