Actually, it does check whether the file is open and it does also show the contents of the file...The only thing that doesn't work is the line count I made. But I see what you mean: Below is the whole code:
unsigned int lc=0;
reDo:
cout << "\n\n\n\n\tUser, please Enter the filename (with directory) below:\n\n\t\t::==:: ";
getline(cin, filename_user);
ifstream read(filename_user.c_str());
if(read.fail())
{
cout << "\n\n\t";
error_slashes();
cerr << "\n\n\t Sorry, but this program was unable to locate/read\n\n\t\t\tthe given file!\n\n\t";
error_slashes();
cin.get();
cout << "\n\n\t\tDo you wish to open a new file? (y/n[quit]) ";
cin >> choice;
if(choice=='y')
{
goto reDo;
}
else
{
exit(1);
}
}
read.open(filename_user.c_str(), ios::in);
while(getline(read, linecount, '\n'))
{
++lc;
}
read.clear();//clear memory
read.close();
read.open(filename_user.c_str(), ios::in);
while(getline(read, lines, '\n'))
{
cout << lines << "\n\n\n";
}
cout << "\n\n\t\t" << lc;
In the code, it checks for the existence of the file before opening...and it does output the file contents...Only thing not working is the line count.
Is the method correct?
Last edited by amrith92; Sep 4th, 2008 at 4:36 am.
"C++ : Where friends have access to your private members."
C++: You accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical assistance is impossible since you can't tell which are bitwise copies and which are just pointing at others and saying, "That's me, over there."