"dsa89" <ds***@vfemail.net> wrote in message
news:ff******************************@localhost.ta lkaboutprogramming.com...
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[i]);
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