J
Jim Langston
Expected output is:
Three
One
One
Actual output is:
Three
One
Two
If I comment out the block that displays the first One, the last line is
blank (in real program it causes memory fault)
#include <string>
#include <iostream>
#include <list>
std::list< std::string > SendHistory;
std::list< std::string >::reverse_iterator SHi;
int main ()
{
SendHistory.push_back( "One" );
SendHistory.push_back( "Two" );
SendHistory.push_back( "Three" );
SHi = SendHistory.rbegin();
std::cout << (*SHi) << std::endl;
// Comment out following three lines changes output
SHi = SendHistory.rend();
--SHi;
std::cout << (*SHi) << std::endl;
// This is the line that's causing problems. Why isn't it working?
SHi-- = SendHistory.rend();
std::cout << (*SHi) << std::endl;
std::string wait;
std::cin >> wait;
}
The line that is causing the problems is:
SHi-- = SendHistory.rend();
Why is that failing? It should be the same as
SHi = SendHistory.rend();
--SHi;
but it's not working the same way. Is this a fault in my compiler maybe?
Microsoft Visual C++ .net 2003
Three
One
One
Actual output is:
Three
One
Two
If I comment out the block that displays the first One, the last line is
blank (in real program it causes memory fault)
#include <string>
#include <iostream>
#include <list>
std::list< std::string > SendHistory;
std::list< std::string >::reverse_iterator SHi;
int main ()
{
SendHistory.push_back( "One" );
SendHistory.push_back( "Two" );
SendHistory.push_back( "Three" );
SHi = SendHistory.rbegin();
std::cout << (*SHi) << std::endl;
// Comment out following three lines changes output
SHi = SendHistory.rend();
--SHi;
std::cout << (*SHi) << std::endl;
// This is the line that's causing problems. Why isn't it working?
SHi-- = SendHistory.rend();
std::cout << (*SHi) << std::endl;
std::string wait;
std::cin >> wait;
}
The line that is causing the problems is:
SHi-- = SendHistory.rend();
Why is that failing? It should be the same as
SHi = SendHistory.rend();
--SHi;
but it's not working the same way. Is this a fault in my compiler maybe?
Microsoft Visual C++ .net 2003