I have no clue why this isn't working! Basically, I've got my tree and
everything working, but now I need to fit it to the input the instructor
gave me. What I need to do is read the first part of a line and then
input each following term into the tree... My problem come with reading
until the end of the line. For some reason, it won't recognise the newline
'\n' character. Right now I'm using strings but I've created a little
sample program below that shows what I'm talking about:
my input looks like this:
I1 kim abelo xxxx abcd xxxy
I2 abelo timmy
D1 kim abelo
D2 timmy
T1
T2
ID
IS
What I'm thinking this code should do is print out that first line only
but it keeps going.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
char temp;
ifstream infile("in.txt");
infile >> temp;
while ((!infile.eof()) && (temp != '\n')) {
cout << temp;
infile >> temp;
}
cout << endl;
return 0;
}
output received:
I1kimabeloxxxxabcdxxxyI2abelotimmyD1kimabeloD2timmyT1T2IDIS
Thanks in advance.