I am trying to create a symbol table based on input from a file.
As of now, I have the code to read the file line-by-line, separate the tokens, and print out the token and its type.
Now, I have to find a way to store these values (token and type) into a symbol table.
I am not familiar with C++ AT ALL. I originally tried to make a multi-dimensional array, but this was a bust because I do no know the amount of lines or tokens a file will have and I could not dynamically set the size of the arrays. Now, I have decided to use a vector of vectors. This is what my line of code looks like:
vector< vector<int> > vec(4, vector<int>(4)) myVector;
I have no idea why it is not working. I copied it exactly from an answer on cplusplus.com. I have also tried
std::vector<std::vector<int> > row;
which was taken from another SO question. I have been searching for hours for the best way to create this table and have run into nothing but problems.
The error I keep getting (as stated in the question) is
error: expected primary-expression before 'int'
How do I solve this?
You need to figure out how you want your object to be called.
If you want to call your object vec
, you should write:
std::vector< std::vector<int> > vec(4, std::vector<int>(4));
If you want to call your object myVector
, you should write:
std::vector< std::vector<int> > myvector(4, std::vector<int>(4));
And if you have "using namespace std;" appearing anywhere in your code, remove it, and forget that you ever saw anything like that.