I have the following code, and it is currently working. However I am trying to read the tokens in three separate ways. The first token or number is to select, the second token, is to select an operation (insert or delete), and the rest of the tokens in the string should be the values to be used. The program is currently able to complete step one and two, but I don't know how to select the rest of the tokens in the string as values to be used to create a binary tree. Please help.
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include<sstream>
using namespace std;
struct trees {
string typet;
string nodes;
string tree;
trees *rec;
};
struct trees lines;
char line[50];
char* token;
int main()
{
ifstream infile;
infile.open("numbers.txt");
if (!infile)
{
// If file doesn't exist.
cout <<"File does not exist... \n\nPlease";
cout <<" verify the file name and try again\n\n"<< endl;
}
while (infile.getline(line, 450))
{
string tree1, operation, data;
istringstream liness(line);
getline( liness, tree1, ',' );
getline( liness, operation, ',' );
getline( liness, data, ',' );
//cout << linea << endl;
cout << "Type of tree: " << tree1 << " Operation to do: " << operation << " Data to use: " << data<< ".\n";
//cout << line << endl;
if (tree1 == "1")
cout<<"It is a binary tree \n\n";
}
infile.close();
system ("pause");
}
This is what it is inside of the text file.
1, 1, 10, 11, 15
1, 1, 13, 20, 14
1, 1, 3, 39. 18
1, 1, 3, 3, 16
First number is to select binary tree, second number means that it will insert in the tree numbers 11 and 15 (using the first line). However my code only reads the first three numbers in every line, I understand that it is because of how it was programmed, but I don't know how to select the rest of the numbers or tokens, excluding the first two numbers that were already used, and then create a binary tree, not using boost libraries.