Expand|Select|Wrap|Line Numbers
- #include<iostream>
- #include<fstream>
- using name space std;
- int main()
- {
- read_emails();
- return 0;
- }
- void read_emails()
- {
- fstream infile;
- char path[100];
- cout<<"Format of the path is like this: c:/tc/test.txt";
- cout<<"Give the path of the file (*.txt or *.dat) to test: ";
- cin>>path;
- infile.open(path, ios::in);
- while(!infile)
- {
- cout<<"Error! can not open the file.";
- //again I prompt the user to give the path of the file
- cout<<"Format of the path is like this: c:/tc/test.txt";
- cout<<"Give the path of the file (*.txt or *.dat) to test: ";
- cin>>path;
- infile.open(path, ios::in);
- }
- }
I have no idea what should be the best solution for this.
My out put trial was
Format of file path-> c:/file.txt
Give the path for the file(txt or dat):c:/tc/email.txt //correct user input
Done!
------------------
LIST OF E-MAILS:
------------------
<nsubedi@hotmail.com>
info@sunaulo.com
sunilraj123@hotmail.com
sunilsthapit@hotmail.com
usunil45@yahoo.com
mailsuniltyata@yahoo.com
sunil_sthapit@csumb.edu
suneeta72@rediffmail.com
sunitasubedi@hotmail.com
Wrote down on the addresses.dat is completed.
Do you want to continue?('Y' for YES of 'N' for NO): y
Format of file path-> c:/file.txt
Give the path for the file(txt or dat):c:/ //User gave the incorrect input for checking
Error! opening file.
choose the correct path
Format of file path-> c:/file.txt
Give the path for the file(txt or dat):c:/tc/email.txt //but this time user gave the corrct file path as user already gave before but It gives Error msg (why?)
Error! opening file.
choose the correct path
Format of file path-> c:/file.txt
Give the path for the file(txt or dat):
y
Error! opening file.
choose the correct path
Format of file path-> c:/file.txt
Give the path for the file(txt or dat):y
Error! opening file.
choose the correct path
Format of file path-> c:/file.txt
Give the path for the file(txt or dat):y
Error! opening file.
choose the correct path
Format of file path-> c:/file.txt
Give the path for the file(txt or dat):y
Error! opening file.
choose the correct path
Format of file path-> c:/file.txt
Give the path for the file(txt or dat):y
Error! opening file.
choose the correct path
Format of file path-> c:/file.txt
Give the path for the file(txt or dat):y
Error! opening file.
choose the correct path
Format of file path-> c:/file.txt
Give the path for the file(txt or dat):c:/tc/email.txt
Error! opening file.
choose the correct path
Format of file path-> c:/file.txt
Give the path for the file(txt or dat):c:/c++/array1.txt
Error! opening file.
choose the correct path
Format of file path-> c:/file.txt
Give the path for the file(txt or dat):