Some modifications on the read function in c++