Click here to Skip to main content
16,010,351 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Folder/File Size?!? Pin
Richard Ellis9-Dec-01 15:44
Richard Ellis9-Dec-01 15:44 
GeneralRe: Folder/File Size?!? Pin
Greven9-Dec-01 17:21
Greven9-Dec-01 17:21 
GeneralRe: Folder/File Size?!? Pin
Ravi Bhavnani11-Dec-01 5:33
professionalRavi Bhavnani11-Dec-01 5:33 
GeneralCMDIChildWnd and CView Pin
9-Dec-01 12:20
suss9-Dec-01 12:20 
Generalsmall question Pin
diego__9-Dec-01 8:19
diego__9-Dec-01 8:19 
GeneralRe: small question Pin
Ravi Bhavnani9-Dec-01 8:38
professionalRavi Bhavnani9-Dec-01 8:38 
GeneralRe: small question Pin
diego__9-Dec-01 8:53
diego__9-Dec-01 8:53 
GeneralReading/Writing in Binary Pin
valikac9-Dec-01 6:09
valikac9-Dec-01 6:09 
Hi,
I have a complicated (to me) problem reading/Writing data in binary. Here is what I am doing.

For example let say a text file has the following:
File: test.txt
-----------------
1234a5678b9
-----------------

Here is what I am doing:

istream inData;
ostream outData;
inData.open("test.txt", ios::in | ios::binary);
outData.open("modified.txt", ios::out | ios::binary);
inData.seekg(0, ios::end);
int size = inData.tellg();

char *temp;
temp = new char[size + 2];

inData.read(reinterpret_cast<char *="">(temp), size);

temp[size + 1] = 'c';
temp[size + 2] = 'd';

outData.write(reinterpret_cast<char *="">(temp), (size + 2);

-----------------------------------------------------

The code above should work okay. As you can see, all I am doing is reading data from a file, add two characters "c" and "d" and then writing it back to the file. Everything is fine.

Now, let say I read the modified file back.

Here is what I am doing:

istream modData;
ostream weird;

modData.open("modified.txt", ios::in | ios::binary);
weird.open("hungry", ios::out | ios::binary);

inData.seekg(0, ios::end);
int size = inData.tellg();

char *temp, charA, charB;
temp = new char[size];

inData.read(reinterpret_cast<char *="">(temp), size);

charA = temp[size - 2];
charB = temp[size - 1];

-----------------------------------------------------

Do you see what I am trying to doing?

1)read fileA in binary
2)save data from fileA to tempX
3)add characters to tempY
4)write temp to fileB

-----------------------
1)read fileB in binary
2)save data from fileB to tempZ
3)extract ONLY those characters I added to tempX from tempZ
-----------------------

The method I use to extract the added characters from the modified file after I read it back is subscript. I assume let say temp[5] is 'a'. When I read the data back, I look at temp[5].

My question is when you read a file in binary, add characters to it in specific spaces and write it to modified file, is it possible to read the data from the modified file and extract those characters you added via assumption subscript? How are data saved when you read and write in binary?

Thanks,
Kuphryn
GeneralRe: Reading/Writing in Binary Pin
Rick York9-Dec-01 6:29
mveRick York9-Dec-01 6:29 
GeneralRe: Reading/Writing in Binary Pin
valikac9-Dec-01 6:40
valikac9-Dec-01 6:40 
Questionrecreating IntelliSense stores ? Pin
Cernd9-Dec-01 6:01
Cernd9-Dec-01 6:01 
GeneralNon-resizable CMainFrame Pin
r2d2rigo9-Dec-01 4:17
r2d2rigo9-Dec-01 4:17 
GeneralRe: Non-resizable CMainFrame Pin
9-Dec-01 5:02
suss9-Dec-01 5:02 
GeneralRe: Non-resizable CMainFrame Pin
r2d2rigo10-Dec-01 10:27
r2d2rigo10-Dec-01 10:27 
GeneralHetrogenous Server/Client Pin
9-Dec-01 4:15
suss9-Dec-01 4:15 
GeneralRe: Hetrogenous Server/Client Pin
Masaaki Onishi9-Dec-01 17:00
Masaaki Onishi9-Dec-01 17:00 
GeneralHelp with network Pin
Philip Patrick9-Dec-01 3:48
professionalPhilip Patrick9-Dec-01 3:48 
QuestionWhat is the difference between "#if !define" and "&#65283;ifnde"? Pin
BigMouth8-Dec-01 17:26
BigMouth8-Dec-01 17:26 
AnswerRe: What is the difference between "#if !define" and "&#65283;ifnde"? Pin
Rick York8-Dec-01 17:52
mveRick York8-Dec-01 17:52 
GeneralRe: What is the difference between "#if !define" and "&#65283;ifnde"? Pin
BigMouth8-Dec-01 18:13
BigMouth8-Dec-01 18:13 
GeneralRe: What is the difference between "#if !define" and "&#65283;ifnde"? Pin
Rick York8-Dec-01 19:19
mveRick York8-Dec-01 19:19 
GeneralRe: What is the difference between "#if !define" and "&#65283;ifnde"? Pin
BigMouth8-Dec-01 20:17
BigMouth8-Dec-01 20:17 
QuestionWhat is the difference between "_DEBUG" and "DEBUG"? Pin
BigMouth8-Dec-01 17:24
BigMouth8-Dec-01 17:24 
AnswerRe: What is the difference between "_DEBUG" and "DEBUG"? Pin
Rick York8-Dec-01 17:44
mveRick York8-Dec-01 17:44 
GeneralRe: What is the difference between "_DEBUG" and "DEBUG"? Pin
BigMouth8-Dec-01 17:59
BigMouth8-Dec-01 17:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.