-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cpp #67
base: master
Are you sure you want to change the base?
Cpp #67
Conversation
Read guest information from input files and print out duplicated information
Solution for week 4
return (m_email < rhs.m_email); | ||
} | ||
|
||
friend std::ostream & operator<<(std::ostream &out, Participant input) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent spacing:
operator< (
operator<<(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you treat this function as a friend
, you don't need to keep its implementation inside the class. Recommended idiom for larger projects:
class A
{
int data;
public:
void print(std::ostream& ostr)
{
ostr << "Data: " << data;
}
};
std::ostream& operator<<(std::ostream& ostr, const A& a)
{
a.print(ostr);
return ostr;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I generally don't recommend having friend
s in C++ ;)
SortedParticipantList eventB; | ||
|
||
// Get file names from command line | ||
GetParticipantListFromFile(argv[1], eventA); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You didn't check if argc == 3
|
||
//------------------------------------------------------------------------------ | ||
|
||
/** Get participant list from input file**/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better way to comment:
/**
* @brief: Get participant list from input file
*/
//------------------------------------------------------------------------------ | ||
|
||
/**Parse a line and add it to the participant list**/ | ||
void ParseParticipantInformation(const std::string &line, SortedParticipantList |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's recommended to have function names start with lowercase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff! Almost perfect! Small changes to make.
{ | ||
|
||
public: | ||
Participant (std::string firstName, std::string lastName, std::string email) : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inefficient: Use const references! const std::string&
//Ignore the first line as title. | ||
std::getline(inputStream, line); | ||
|
||
const std::regex pattern("(\\w+),(\\w++),([A-z0-9._%+-]+@\\w+\\.\\w+)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this match names like O'Reilly
or van Derks
? I don't think so.
Solution for week 4