std::string line_format_for_total ( const std::string title,
constlonglong val )
{
std::stringstream ss;
std::string rt ;
ss << title ;
ss << std::setw(FIELD_WIDTH_SZ) ;
ss << format_with_commas ( val / 100.0 , 2 );
ss.flush () ;
rt = ss.str();
// return ss.str(); <---this is how it was originally written.
return rt;
}
std::string line_format_for_col ( const std::string title1,
const std::string title2 )
{
std::stringstream ss;
std::string rt ;
ss << title1 ;
ss << center_on(title2, FIELD_WIDTH_SZ) ;
ss.flush () ;
rt = ss.str();
// return ss.str(); <---this is how it was originally written.
return rt;
}
These functions work, but when written the original way they would work if one was called but not if they were both called.
I spent at least five hours trying to figure out what was wrong; because why it broke made no sense to me. If I call only one of the functions in the program or tested them separately there was no problem.
These functions work, but when written the original way they would work if one was called but not if they were both called.
* If a comment-out either function call the program will run without error.
*But when I try to call them both the program does not run.
* If you look at the code I wrote you will see I placed a comment that shows how they were originally written. It is a runtime error the program compiles without error, but when written the original way it is stopped by the operating system with a message that says the program has been stopped.
* More confusing is the fact that when I run this same program at home I can run it either way and they both work. I did recompile the program so it is not the same program--but both were compiled with the same compiler (gcc-4.7.0).
* I would also appreciate a little more detailed criticism because I really do not understand why you feel that this question was not asked in the smart way.
problem is somewhere else. format_with_commas() center_on()
I did not write the format_with_commas I copied from somewhere--I actually do not
understand why it works. If it is the problem I can rewrite that function more simply.
I probably should not use code I don't personally understand.
I posted the code below in hope that maybe someone else can spot the problem.