So what I have is a piece of code like this:
int newMessages = 0;
for (unsigned int i = 0; i < listToFill.size(); i++)
{
if (listToFill[i].getUnread() == "N") // checking if the message is new
{
newMessages++; // if it is, this variable gets increased
}
// cout << listToFill[i].getUnread() << " "; // this is a test code to make sure the getUnread status exists
}
|
listToFill is a vector filled with classes, getUnread is a member function of the class that returns the status of the object, which is either "N" for new or "R" for read. Now for some reason, when I print the newMessages variable after this code, it still says 0 instead of 1, meaning it's not comparing the two "N"s properly for some reason.
If I change the operator to != "N", the newMessages variable will then be 5, meaning nothing in the vector's status matches the N. Also if I uncomment the test part code, it outputs: R R R R N, meaning that the strings SHOULD exist in the variable.
getUnread returns a string that is either N or R, and "N" on the right hand of the operator should be a string, so why isn't this comparing the two properly?
Seems so simple, but I can't figure this out. Thanks to anyone who replies!