I am working on a c++ project on the g++ compiler for linux.
The goal is to create a phone directory with entries composed of first name, last name, and phone number.
I have everything written with no compile errors, and it passes all tests but one where it uses << operator to pass and entry 'e' to an ostringstream and compares o.str() to an expected string. I have printed 'e' and o.str() to the console screen during the tests and they seem to match except a "mysterious" new line that gets inserted after o.str() is printed.
code from the my entry.cpp and tester.cpp and console output follow.
My question is two fold. Where does this new line get inserted and where/what is it that makes my test fail? Thanks in advance for any advice.
/// verifies the operator<<
void test_entry_out() {
ostringstream o;
entry e("Orlando","Karam","5555");
o << e;
cout<< "Attempting to print o.str() " << o.str() << " Attempting to print o " << o << " Attempting to print e " << e << " finished";
CPPUNIT_ASSERT(o.str()=="Orlando:Karam:5555");
}
Output from the test cases
....Attempting to print o.str() Orlando:Karam:5555
Attempting to print o 0xbfb02850 Attempting to print e Orlando:Karam:5555
finishedF....
!!!FAILURES!!!
Test Results:
Run: 8 Failures: 1 Errors: 0
1) test: tester::test_entry_out (F) line: 69 tester.cpp
assertion failed
- Expression: o.str()=="Orlando:Karam:5555"