If your doing command line you can pass it as an arg... I would think at least.
I don't know the PGM layout, but you can use this general code to read from a file. Whitespace will break the read by the way so we don't always grab 80 chars of data just seperate chunks this might help some.
using namespace std;
int main(int argc, char* argv)
filepath = new char[strlen(argv)+1];
infile>>var1; //loop this to read next chunk of data