Basically, what I'm trying to do is to read and load a tree structure from a file to an unordered_map.
Example of a tree structure:
<index> <attribute> <operator> <value> <no> <yes> %optional comment
0 height > 180.0 1 basketball %first node
1 weight > 50.0 athletics basketball
For now, I've written code that would display the tree structure: (with no comments, currently also working on it ignoring comments)
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <string>
struct Node {
int index;
std::string attribute;
char oper;
double value;
std::string no, yes;
};
int main()
{
std::ifstream filetree(">
The problem is, I was instructed to use the following variable types:
<pre>int index;
std::string attribute;
bool oper;
double value;
int no, yes;
And, using these variable types, nothing is displayed.
While debugging, it is shown that node.oper is false (which is understandable, because of it being a '>' or a '<'), node.value is equal to
-9.2559631349317831e+61, while both node.no and node.yes are equal to
-858993460.
If I put the
std::cout<<node.index...
outside of the
while(filetree>>node.index...
The previously mentioned values are displayed(-85899...), but only in 1 line (what shouldve been 2 lines)
My main problem is handling the bool and int type variables, in that case int being a word ("basketball" for example) and bool being one of two characters ('>' or '<')
Later on, I will have to use the tree structure to classify data, but I have to tackle this problem first.
What I have tried:
Reading about variable type conversions - due to being a huge beginner of a programmer I couldnt think of any solution using conversions