473,385 Members | 1,940 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,385 software developers and data experts.

Q regarding a strange behavior when using ifstream

4
Hi,

I now run into a very strange behavior when using ifstream. Can anyone please help me out here:

Basically, what I want to do is to encrypt a plain text file into a cipher text and then decrypt it back to the plain text file. I use ifstream to read the file into the buffer. Let's say the size of my encrypted file is 816 bytes. Normally after opening the file and calling the inf.read(garbage, 16), the get pointer should be moved from the ios::beg forward 16 bytes and therefore length is equal to 16. This is the result I get from when running this code against the plain text file. But things are different when I use this code to read the encrypted file. After opening the encrypted file and calling the inf.read(...), length is equal to 672. If I call the inf.read(...) again, then the get pointer moves 16 bytes forward and length is equal to 688. How come the get pointer jumps directly to the position 672?

Thanks

my code:

Expand|Select|Wrap|Line Numbers
  1. char garbage[16];
  2. int length;
  3.  
  4. ifstream inf;
  5. inf.open("fileName");
  6. inf.read(garbage, 16);  
  7. length = inf.tellg();
Nov 5 '07 #1
2 1953
weaknessforcats
9,208 Expert Mod 8TB
Have you tried opening the encrypted file as binary??
Nov 5 '07 #2
Pinux
4
Have you tried opening the encrypted file as binary??
You got me. Thank you so much!!!!!!!!!!
Nov 5 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: matthias_k | last post by:
Hi, I am currently implementing a solver for linear optimization problems using the revised simplex method and I stumbled accross some strange behavior regarding the treatment of the number 0....
1
by: Alex Vinokur | last post by:
I have several questins concerning a program below. ------ foo.cpp : BEGIN ------ #include <cassert> #include <cstdlib> #include <iostream> #include <fstream> using namespace std; int...
3
by: Karl M | last post by:
Hi everyone, I just notice some strange behaviors on the MS C++ compiler regarding struct default constructor, see the example bellow: struct MyStruct { int a; }; class MyClass { public:
6
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the buttons and menu items are wired up to send events to...
1
by: beatTheDevil | last post by:
Hello all, I have a question that concerns how C++ input streams (istream, ifstream, istringstream, etc.) behave using the extraction (>>) operator when at the end of a stream's contents. For...
8
by: somenath | last post by:
Hi All, I have a doubt regarding the pointer assignment . Please have a look at the following program . #include<stdio.h> #include<stdlib.h> #define NAMESIZE 10 #define SAFE_FREE(t) if(t)\...
5
by: Philip Potter | last post by:
I have a somewhat flippant question regarding undefined behaviour. Does an operation which invokes undefined behaviour affect the whole program, or are earlier statements guaranteed to execute...
6
by: zl2k | last post by:
hi, there I have a appendable binary file of complex data structure named data.bin created by myself. It is written in the following format: number of Data, Data array Suppose I have...
0
by: charmeda103 | last post by:
when i run my program it runs with no erorrs but the output screen is giving me strange results here is whats its giving me: CONFERENCE OVERALL RANK TEAM W-L % WINS MARGIN W-L ...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.