Mar 8, 2012 at 3:40pm UTC
So for this program... I'm trying to read from a .txt file in a very specific format. I have a function...that looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
void Read_Roster(Maple Roster[], int &count)
{
cout << "Reading Function" <<endl;
//-------------------
// Opening input file
//-------------------
ifstream din;
din.open("south.txt" );
if (din.fail())
cout << "Could not open File" << endl;
//--------------------------------
// Reading file.
//--------------------------------
string str;
getline(din, str);
//--------------------------------
// Loop reading file
//--------------------------------
for (int i=0; i<count && !din.eof(); i++)
{
getline(din, str);
Roster[i].setName(str);
getline(din, str);
Roster[i].setID(str);
getline(din, str);
Roster[i].setRoom(str);
getline(din, str);
Roster[i].setCombo(str);
getline(din, str);
Roster[i].setEMail(str);
getline(din, str);
Roster[i].setMB(str);
Roster[i].print();
}
//--------------------------------------
// Closing input file
//--------------------------------------
din.close();
}
for some reason it is not working... at all...
the .txt file looks like this:
Wayne, Bruce
15813u513
BA-214 FOB # 13513
14-13-12
a@whatever.edu
MB 0313
Wayne, John
15813u513
BA-114 FOB # 16144
14-13-22
ab@whatever.edu
MB 0323
Wayne, Frank
15813u513
BA-314 FOB # 11333
14-33-12
ac@whatever.edu
MB 0413
i have each line reading as a string...and when i try to print..it does not work..
my print function looks like this..
1 2 3 4 5
void Maple::print()
{
cout <<"Name: " << Name << "ID: " << ID <<"Room: " << Room<<"Combo: " << Combo <<"E-Mail: " << EMail << "MB: " << MB <<endl;
}
Last edited on Mar 8, 2012 at 4:08pm UTC
Mar 8, 2012 at 4:02pm UTC
When you say 'does not work' what do you mean? Give us examples of your output.
Mar 8, 2012 at 4:04pm UTC
when i do ./a.out it simply terminates.. i tried putting cout<<"test"<<endl; in between each setName, setID, setCombo, setMB, setEMail but it does not work..i made sure that it recognizes the .txt file and the contents..but i'm stumped.
Mar 8, 2012 at 4:05pm UTC
I mean..if i'm setting each line of code from the file, shouldn't it print after each iteration?
Last edited on Mar 8, 2012 at 4:08pm UTC
Mar 8, 2012 at 4:11pm UTC
Your problem isn't in that function, then, because if you're not getting at least "Reading Function" printed to the console, then you're never even entering the function that reads from south.txt
Mar 8, 2012 at 4:13pm UTC
cindyath@tuning:~/test/testl$ ./3
Test program
Reading Function
Mar 8, 2012 at 4:13pm UTC
I know for certain it's the function.. I'm just rather amused as to what in the world could be the error.
Mar 8, 2012 at 4:17pm UTC
Show the declaration of your Maple class.
Mar 8, 2012 at 4:39pm UTC
:P That's the definition. I wanted the declaration.
Mar 8, 2012 at 4:49pm UTC
Your declaration (.h file) says
void setMB(string MB); // Note the variable name in uppercase
Your definition (.cpp file) says
void Maple::setMB(string mb) // Note the variable name in lowercase
The variable names don't match in the definition and declaration.
Mar 8, 2012 at 4:52pm UTC
okay that's fixed...but it's still doing the same thing... there is a problem with the reading function.
cindyath@tuning:~/test/testl$ ./3
Test program
Reading Function