C++ Array of structures. (n00b help)
Posted: Thu Mar 23, 2006 5:35 pm
OK excuse the n00biness here but I'm just learning (GNU) C++ here and there 
I'm going to try converting some PHP code into C++ that I wrote (a tokenizer). I think I'm going to need an array that contains a fixed number of elements, each of which is a very simple structure. Maybe I need a linked list instead but I haven't quite worked that out yet
OK I know how to initialize an array of say, integers with a list of values:
But how would I do that with a list of structures? (I need to assign values to the properties of the structure).
Meh, I do think I need a linked list... I'll start reading (again)
The array hold defintions for a load of tokens that in PHP I was doing with a multi-dimensional array like this:
But in C++ a structure seems more sensible to keep the definition grouped closely (?).
Cheers if anyone can push me in the right direction
I'm going to try converting some PHP code into C++ that I wrote (a tokenizer). I think I'm going to need an array that contains a fixed number of elements, each of which is a very simple structure. Maybe I need a linked list instead but I haven't quite worked that out yet
OK I know how to initialize an array of say, integers with a list of values:
Code: Select all
int foo[] = { 1, 2, 3 };Code: Select all
#include <iostream>
using namespace std;
//A pattern and a 1 or a 0
// depending upon if the
// pattern is a regex
struct tokDef
{
char *pattern;
char *tokName;
int re;
};
//The array we'll store our defintions in
tokDef defintions[] = {
/** How can I add some values here? **/
};
int main()
{
//
return 0;
}The array hold defintions for a load of tokens that in PHP I was doing with a multi-dimensional array like this:
Code: Select all
$tokenDefs = array(
'TOKEN_ONE' => array('/\bfoo\d{2}/', 1),
'TOKEN_TWO' => array('::', 0)
);Cheers if anyone can push me in the right direction