473,761 Members | 5,848 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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->10001010101010 1010....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*******@comca st.net
Paul
Nov 25 '06 #1
4 1908

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->10001010101010 1010....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_ba ck( 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( "00010011100010 100010" ); // test
std::bitset<32B its( Bits32 );
std::cout << Bits << std::endl;

Bits>>=5;
std::cout<<"Bit s>>=5;\n"<< Bits << std::endl;
Bits&=24;
std::cout<<"b&= 24;\n"<< Bits <<std::endl;
}
std::ifstream Tfile("SomeName .txt", std::ios::binar y);
.....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*******@comca st.net
Paul

----- Original Message -----
From: "BobR" <Re***********@ worldnet.att.ne t>
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->10001010101010 1010....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_ba ck( 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( "00010011100010 100010" ); // test
std::bitset<32B its( Bits32 );
std::cout << Bits << std::endl;

Bits>>=5;
std::cout<<"Bit s>>=5;\n"<< Bits << std::endl;
Bits&=24;
std::cout<<"b&= 24;\n"<< Bits <<std::endl;
}
std::ifstream Tfile("SomeName .txt", std::ios::binar y);
....is not what you seem to think.

--
Bob R
POVrookie
"BobR" <Re***********@ worldnet.att.ne twrote in message
news:qS******** *************@b gtnsc04-news.ops.worldn et.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->10001010101010 1010....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_ba ck( 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( "00010011100010 100010" ); // test
std::bitset<32B its( Bits32 );
std::cout << Bits << std::endl;

Bits>>=5;
std::cout<<"Bit s>>=5;\n"<< Bits << std::endl;
Bits&=24;
std::cout<<"b&= 24;\n"<< Bits <<std::endl;
}
std::ifstream Tfile("SomeName .txt", std::ios::binar y);
....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_er ror( " 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<32B its( 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*******@comca st.net

Paul...
Dec 3 '06 #5

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

Similar topics

2
3930
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 them a caption, storing the caption and filename in a text file. It's a bit buggy when removing the photos and captions from the file, and also in displaying them on the delete page. you can see it in action at www.4am.com.au/gallery/upload.php...
18
9114
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 data, imports it into a mySQL database and deletes the .csv-file after the import. so far, so good. but in some cases the cronjobs starts running when the file is not completely
3
4607
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 "file.tell() and file.seek() in order to navigate through a file in order to print specific lines (for example, every 5th line). Allow me to illustrate by example:
7
3538
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. How do i make the last pointer in the indirect sector that has another level of indirect pointer, and be defined recursively to support infinite large files? -code-
0
3940
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. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header, example, and DLL:...
0
2572
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 datalist. When the next user selects trys to run the page, the page fails and I get a generic error message from the stack trace. I am assuming that the document properties cannot be read when a file is open, but it worked well in asp. ...
1
3202
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 ... - Crystal_Database_Access2003.msm - Crystal_Database_Access2003_enu.msm - Crystal_Managed2003.msm - Crystal_regwiz2003.msm ....and suddenly my <MyApplication>.msi - file was quite big, about 10MB!
0
2031
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 said to me that they have no problem doing that, but the following project file is said to be corrupted while opening in the IDE, it is the project file of NT xemacs BETA 21.5.24, http://ftp.xemacs.org/pub/beta/xemacs-21.5.24.tar.gz (under the...
17
8029
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: I am trying to use the SaveFileDialog class to get a filename, which is subsequently opened for writing (write access, read sharing, but using read/write sharing doesn't make the problem go away anyway). Sometimes, on the statement where I...
2
2842
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 wireless where I'm working could just be ungodly slow-- which it is.) Is reading a file much more resource/processor intensive than, say, including a .php file? What about the act of creating a simpleXML object? What about the act of checking the...
0
9336
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10111
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9948
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8770
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6603
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.