I am trying to do simple file IO whereby I read in three integers from a file.
INPUT File:
4 4 1
4 4 1
C++ CODE:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int el_shape =0;
int nNodes =0;
int nElems =0;
// Open the control file
ifstream file;
file.open(filename.c_str());
if(!file.is_open())std::cout<<filename+" does not exist! Exit"<<std::endl;;
char name[256];
file.getline(name,256);
std::cout<<name<<std::endl;
file>>el_shape >> nNodes >> nElems;
std::cout<<el_shape<<" "<<nNodes<<" "<<nElems<<std::endl;
PROGRAM OUTPUT:
4 4 1
0 0 0
Does anyone have an idea as to why the values of the variables el_shape, nNodes, and nElems are not updating using "file>>el_shape>>nNodes>>nElems;" ? This would seem trivial to me but as seen in the output, it's not working!