Hi,
I have a program that must read from a file and insert each line into a binary search tree.
I've already written all needed code to read from file and insert into the tree. My problem is that when i get the data from the file and insert into the tree, the data is not inserted.. but it's the address of the char that is there.
Any thoughts about this please?
void readFile(const char *fileName, BST myBST)
{
ifstream inFile; //file object
char temp[10];
inFile.open(fileName, ios::in); //open input file
if (!inFile) {
cerr << "Cannot open input file '" << fileName;
exit(1);
}
while (!inFile.eof()) {
inFile >> temp;
cout << temp << endl;
BSTusers.insert(temp); //PROBLEM IS HERE
}
}
I'm not sure how to retrieve the contents of the char array.
Note that the "cout << temp" prints out the correct data and when i do BSTusers.insert("hello", the string 'hello' is inserted just fine.
Any help would be much appreciated.
Thanks!
I have a program that must read from a file and insert each line into a binary search tree.
I've already written all needed code to read from file and insert into the tree. My problem is that when i get the data from the file and insert into the tree, the data is not inserted.. but it's the address of the char that is there.
Any thoughts about this please?
void readFile(const char *fileName, BST myBST)
{
ifstream inFile; //file object
char temp[10];
inFile.open(fileName, ios::in); //open input file
if (!inFile) {
cerr << "Cannot open input file '" << fileName;
exit(1);
}
while (!inFile.eof()) {
inFile >> temp;
cout << temp << endl;
BSTusers.insert(temp); //PROBLEM IS HERE
}
}
I'm not sure how to retrieve the contents of the char array.
Note that the "cout << temp" prints out the correct data and when i do BSTusers.insert("hello", the string 'hello' is inserted just fine.
Any help would be much appreciated.
Thanks!