fstream hfile; hfile.open("c:\\1.txt", ios::out | ios::in, _sh_denywr); //only deny write string str; while(std::getline(hfile, str)) cout << str << endl; hfile.close();