You are not include algorithm for std::count.
instructionCount = count(file.begin(), file.end(), ',');
I am actually even surprised that it builds with clang because it should not, and it does not compile for me.
It might have something to do with internal implicit include clean up as there used to be gcc variants where some includes were implicit and it was hidden for the developer that they are actually explicitly depending on something. This is not a good practice. Always include explicitly what you use.
You have to amend this at the top:
#include <algorithm>
Also, note that when you write this line:
ifstream rdfile(filename);
It means you will need to use the -std=c++11
option for the compiler, let it be gcc or clang because that constructor type for ifstream that accepts std::string was only introduced in C++11.
For any previous version, you would need to change filename
to filename.c_str()
to get the char* name of the file.
Therefore, this is how I made your code compiling after adding the extra explicit include:
g++ -std=c++11 main.cpp
and
clang -std=c++11 main.cpp