•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 391,588 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,634 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 3060 | Replies: 2
![]() |
•
•
Join Date: Nov 2004
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
I need help ladies and gentlemen, I am writing a program that validates ISBN numbers both from file and from console input. However my program is unable to open the file even though I have it in my Debug folder. Here is a piece of my code. I need help urgently;
int main()
{
ifstream fin;
int choice; //selected option from the menu
fin.open(inData);
char line[100];
cout<<" ISBN VALIDATOR"<<endl;
cout<<" ****************"<<endl;
do
{
//the printing of the menu
cout<<endl<<"MENU OPTIONS:"<<endl;
cout<<"1. READ ISBNs FROM CONSOLE"<<endl;
cout<<"2. READ ISBNs FROM FILE (isbntest.txt)"<<endl;
cout<<"3. EXIT"<<endl;
cout<<"PLEASE ENTER YOUR CHOICE:";
cin>>choice; //read the user choice
switch(choice)
{
case 1:
cout<<"PLEASE ENTER ISBN NUMBER:";
cin>>line;
//showResult(line); //reads the ISBN from the console and check it
break;
case 2:
char n;
ifstream fin;
fin.open("isbntest.txt");
//ifstream fin(inData); //opens the file isbntest.txt
if (fin.is_open()) //if the opening succeeded
{
fin>>n; //reads the number of tests
for(int i=0;i<n;i++)
{
fin>>line; //reads each ISBN
showResult(line); //and check if is correct
}
fin.close();
}
else
cout<<"COULD NOT OPEN THE FILE <isbntest.txt>."<<endl;
//break;
}//switch
}//do
while(choice!=3); //repeat printing the menu until the user chooses option 3
return 0;
}//main
int main()
{
ifstream fin;
int choice; //selected option from the menu
fin.open(inData);
char line[100];
cout<<" ISBN VALIDATOR"<<endl;
cout<<" ****************"<<endl;
do
{
//the printing of the menu
cout<<endl<<"MENU OPTIONS:"<<endl;
cout<<"1. READ ISBNs FROM CONSOLE"<<endl;
cout<<"2. READ ISBNs FROM FILE (isbntest.txt)"<<endl;
cout<<"3. EXIT"<<endl;
cout<<"PLEASE ENTER YOUR CHOICE:";
cin>>choice; //read the user choice
switch(choice)
{
case 1:
cout<<"PLEASE ENTER ISBN NUMBER:";
cin>>line;
//showResult(line); //reads the ISBN from the console and check it
break;
case 2:
char n;
ifstream fin;
fin.open("isbntest.txt");
//ifstream fin(inData); //opens the file isbntest.txt
if (fin.is_open()) //if the opening succeeded
{
fin>>n; //reads the number of tests
for(int i=0;i<n;i++)
{
fin>>line; //reads each ISBN
showResult(line); //and check if is correct
}
fin.close();
}
else
cout<<"COULD NOT OPEN THE FILE <isbntest.txt>."<<endl;
//break;
}//switch
}//do
while(choice!=3); //repeat printing the menu until the user chooses option 3
return 0;
}//main
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,646
Reputation:
Rep Power: 18
Solved Threads: 191
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
3d apple cocoa computer dell development drivers email eudora firefox fortitude framework games graphics hope ibm intel internet java links linux microsoft microsystems mozilla news next open open source open-source opengl openoffice operating penelope profits programming red hat software source step struggle sun super system trial-and-error ubuntu victory vista wesnoth windows xp
- Error message when attempting to run program in Windows XP (Windows NT / 2000 / XP / 2003)
- Error message upon startup - PLEASE HELP!! (Viruses, Spyware and other Nasties)
- Loading external file from within program (Visual Basic 4 / 5 / 6)
- need help with uninstalling VS Pro 6.0 (Visual Basic 4 / 5 / 6)
- Visual Basic Error message! (Visual Basic 4 / 5 / 6)
- error message whe installing a program (Windows NT / 2000 / XP / 2003)
Other Threads in the C++ Forum
- Previous Thread: i don't know how to start
- Next Thread: which version you recommend ?



Linear Mode