vendredi 3 avril 2015

how to separate tokens, using multiple ways


Vote count:

0




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 {
//const int size = 30;
//const int selector = 10;
//char linea[size];
char typet [5];
char nodes[30];
char tree [15];
trees *rec;
};

struct trees lines;
char line[50];
char* token;

int main()
{

ifstream infile;
infile.open("numbers.txt");
if (!infile)
{
// En caso el archivo no exista.
cout <<"File does not exist... \n\nPlease";
cout <<" verify the file name and try again\n\n"<< endl;
}

while (infile)
{
// read another record
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 << "Tipo 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";
}//end of inner while
}

}// end while

infile.close();

system ("pause");
}


asked 37 secs ago







how to separate tokens, using multiple ways

Aucun commentaire:

Enregistrer un commentaire