473,387 Members | 3,820 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,387 software developers and data experts.

Multiple Vectors Output/Input into binary file?

1
How do you read from a binary file into a structure that contains multiple vectors?

For example

struct studentRecords
{
string user;
vector<string> friends;
vector<string> enemies;
}

From what i gather if i wanted to output that data structure into a binary file i would need to create my own write function that iterates through the variables in the data structure and also each vector element

Such as:
void writeToFile()
{
//create fstream etc.
myFile.write << user
for(int i=0; i< friends.size(); i++)
write << friends[i];

for(int i=0; i< friends.size(); i++)
write << enemies[i];
}

which seems fine but when i want to read the details of the binary files into a new data structure, how do it do this when vector1(friends) and vector2(enemies) might not be the same length?

How do i find the size of a vector stored into a binary file?

Thanks in advanced
Apr 6 '08 #1
3 2720
weaknessforcats
9,208 Expert Mod 8TB
As with all disc file reading, unless you know the format of the file, you can't read it.

That is, when a file contains friends and enemies it is presupposed you know what's in the file in order to read it.

If friends an emenies can be intemingled in the file, then you need to write out a packet that contains and indentifer (friend or enemy) and a length of the item floowed by the item itself. That way when you read, you can read the identifier and know what you are reading and how long it is.

Otherwise, you use two files. One for friends and one for enemies.
Apr 6 '08 #2
mad106
2
What if i have controls on a form that i wan to read and write


As with all disc file reading, unless you know the format of the file, you can't read it.

That is, when a file contains friends and enemies it is presupposed you know what's in the file in order to read it.

If friends an emenies can be intemingled in the file, then you need to write out a packet that contains and indentifer (friend or enemy) and a length of the item floowed by the item itself. That way when you read, you can read the identifier and know what you are reading and how long it is.

Otherwise, you use two files. One for friends and one for enemies.
Oct 6 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
You will have to unload the data from the form and write in a format that you can read back and load another form of the same type. The form itself will not be in the disc file.
Oct 6 '08 #4

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

Similar topics

10
by: mahurshi | last post by:
I've got a gate structure that looks like this /* Defining sGATE structure */ struct sGATE { string name; vector<int> input; int output; };
3
by: Arun | last post by:
Hi, I have simple question to ask. How to write multiple Binary files to the Browser using Asp.Net and Visual C#.net I have seen examples where single binary file is written to browser. ...
5
by: Jeff | last post by:
We are using .Net and the wsdl Utility to generate proxies to consume web services built using the BEA toolset. The data architects on the BEA side create XML schemas with various entities in...
3
by: John Williams | last post by:
I'm writing a stagenography program to experiment with how it works. The algorithm I'm using appears to be producing the correct result...however I'm struggling with the file input. I never...
5
by: arnuld | last post by:
/* C++ Primer 4/e * STATEMENT * given 2 vectors of integers, write a programme to determine whether one vector * is the prefix of the other vector e.g. if 1st vector has elements...
1
by: yohan610 | last post by:
i have to read the binary data of a file, then encrypt them according to a supplied algorithm...and then the obtained output has to be written to an output file...everything works ok, and there are...
3
by: nigelesquire | last post by:
Please help! I'm trying to clone and delete multiple rows with JavaScript. I need two delete buttons that work...! I only have one for now, but it's not working properly, the output count is...
1
by: deepaks85 | last post by:
Dear All, I want to send some data through a form with Multiple attachment in an HTML Format. I have tried it but it is not working for me. I am able to send data without attachment but with the...
10
by: sagitalk | last post by:
Here is my code: #include <iostream> #include <vector> #include <fstream> #include <stdio.h> #include <string> #include <cstring> using namespace std;
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$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...

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.