Data Structure and making the size change

D

dsa89

I would like to know if anyone can help me with this. I would like to load
a file into a data structure but dont know how. Here is an example file.

;File Example
;Created 03/04/99
[Command]
name = "2QCF_y"
command = ~D, DF, F, D, DF, F, y

[Command]
name = "5b"
command = b, b, b, b, b
time = 30
etc....

My question is if someone can help me to load any file (I know how to
open it) but then input it into a data structure where each case is

command = ......

My problem is making the data structure increase or decrease depending on
the number of commands. Can anyone help me with this by pointing me in the
right direction A little code would be nice but an explanation is just as
good. Thanks
 
J

John Harrison

dsa89 said:
I would like to know if anyone can help me with this. I would like to load
a file into a data structure but dont know how. Here is an example file.

;File Example
;Created 03/04/99
[Command]
name = "2QCF_y"
command = ~D, DF, F, D, DF, F, y

[Command]
name = "5b"
command = b, b, b, b, b
time = 30
etc....

My question is if someone can help me to load any file (I know how to
open it) but then input it into a data structure where each case is

command = ......

My problem is making the data structure increase or decrease depending on
the number of commands. Can anyone help me with this by pointing me in the
right direction A little code would be nice but an explanation is just as
good. Thanks

C++ has lots of data structures built in. One of the simplest to use is
called a vector. Here's a little sample

#include <vector>
#include <string>

struct Command
{
std::string name;
std::string command;
int time;
};

// here's your vector of commands
std::vector<Command> command_vector;

// here's how to add a command to the command vector
Command a_command;
command_vector.push_back(a_command);

// here's how to loop though all the commands
for (int i = 0; i < command_vector.size(); ++i)
print_command(command_vector);

etc. etc.

Any decent C++ book will talk about the vector class and a whole lot more.
Perhaps you need to invest in one?

john
 
D

dsa89

Just in a little hurry and am coding in c++ for the first time. Yes, I will
invest in one.

So that code will work for what I am looking for, or would I need to
expand it? Add something or other?

Thanks.
 
J

John Harrison

dsa89 said:
Just in a little hurry and am coding in c++ for the first time. Yes, I
will
invest in one.

So that code will work for what I am looking for, or would I need to
expand it? Add something or other?

Thanks.

You will need to expand it A LOT.

Are you an experienced programmer (even if not in C++). You seem to have
given yourself quite a difficult and tedious project for a first attempt at
C++.

Are you sure that C++ is the most suitable language. Nothing in C++ makes it
especially suitable for what you have described so far. I would choose to do
this in C++ but only because I'm very familiar with the language, if you are
more familiar with a different language it might be better to stick with
that.

If you have programmed other languages before then 'Accelerated C++' by
Koenig and Moo might be suitable, but no-one learns C++ in a hurry.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top