Hi,
Can you show the code where you call the functions?
It looks to me that input is going to stop as soon as a non-double is encountered, so it will indeed only read 1 line given your input file. Or at least the value returned will be 1, so will not match the expected value from map[0], hence the
break
. You can find this out for yourself by using a debugger - it will save you
days of staring at code
Btw,
map
is not a good name for a variable - you must have
using namespace std;
- there is potential for confusion there. In the end it is best to pre-pend every std thing with
std::
Also, your return type should be
std::size_t
, because this is what
size()
functions return.
The break statement (in a while loop that runs until the end of the file is reached): |
I hope you are not looping on
eof
:+)
Both of your functions are nearly identical, except for the
"O"
or
"I"
, you could send those values as a parameter, and have one function. Code duplication is something to be avoided. In that case the type of operation being performed is shown by the variable name the result is assigned to, and the vector being sent as an argument.
Hope this helps :+)