Forgive me as I am new to using debuggers to find problems in m program, I got it set up, at least I think I did it right, I set a break point when it sets seekg(0) in showAllRecords() and followed it through, after altering the data in the file the program would get stuck at the "if (person.getId() != 0)" check and would just bounce through line 150 to 155, never getting to the print line or to read the next set of data.
So I removed the if check and now it just crashes with a segmentation fault, I dont know how to get more information about why this is but it references the PersonData object, with i assume a stack trace:
#0 0x7ffff69c63d0 ??() (/lib64/libc.so.6:??)
#1 0x7ffff7217532 std::string::_Rep::_M_clone(std::allocator<char> const&, unsigned long) () (/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/libstdc++.so.6:??)
#2 0x7ffff7217c3c std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&) () (/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/libstdc++.so.6:??)
#3 0x4029d9 PersonData::getLastName(this=this@entry=0x7fffffffdb40) (/home/bobby /cpp/FileIOPerson/PersonData.cpp:37)
#4 0x401bb3 outputLine(output=..., person=...) (/home/bobby/cpp/FileIOPerson/main.cpp:85)
#5 0x40234f outputAllRecords(fileToPrint=...) (/home/bobby/cpp/FileIOPerson/main.cpp:155)
#6 0x4016cd main() (/home/bobby/cpp/FileIOPerson/main.cpp:52)
It brings focus to the #3 line, PersonData:getLastName(this=this@entry0x7fffffffdb40) so Ill put the code for PersonData up to but if you could just tell me where this is asking me to look at then id be grateful, because there is nothing wrong with getLastName to me, its just a return statement.
PersonData.h:
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
|
#ifndef PERSONDATA_H
#define PERSONDATA_H
#include <string>
using namespace std;
class PersonData
{
public:
PersonData( int = 0, string = "unassigned", string = "", int = 0);
// accessor functions for id
void setId( int );
int getId() const;
// accessor functions for lastName
void setLastName( string );
string getLastName() const;
// accessor functions for firstName
void setFirstName( string );
string getFirstName() const;
// accessor functions for age
void setAge( int );
int getAge() const;
private:
string lastName;
string firstName;
int age;
int id;
};
#endif // PERSONDATA_H
|
and PersonData.cpp
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 58 59 60 61 62
|
#include <string>
#include "PersonData.h"
using namespace std;
// default constructor
PersonData::PersonData( int idValue, string lastNameValue, string firstNameValue,
int ageValue )
{
setId( idValue );
setLastName( lastNameValue );
setFirstName( firstNameValue );
setAge( ageValue );
} // end function PersonData
// set ID
void PersonData::setId( int idValue )
{
id = idValue;
} // end function setId
// get ID
int PersonData::getId() const
{
return id;
} // end function getId
// set last name
void PersonData::setLastName( string lastNameValue )
{
lastName = lastNameValue;
} // end function setLastName
// get last name
string PersonData::getLastName() const
{
return lastName;
} // end function getLastName
// set first name
void PersonData::setFirstName( string firstNameValue )
{
firstName = firstNameValue;
} // end function setFirstName
// get first name
string PersonData::getFirstName() const
{
return firstName;
} // end function getFirstName
// set age
void PersonData::setAge( int ageValue )
{
age = ageValue;
} // end function setAge
// get age
int PersonData::getAge() const
{
return age;
} // end function getAge
|
Thanks....