By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,136 Members | 1,089 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,136 IT Pros & Developers. It's quick & easy.

cant find the prob!!HELP

P: 24
hi can anyone help me with this prog. cant find the prob why it cant display

Expand|Select|Wrap|Line Numbers
  1.     cout<<"This is the display of your transaction"<<endl;
  2.  
  3.                 ifstream fobj;  //declare input file stream
  4.  
  5.                 fobj.open("trans.txt"); //open file
  6.  
  7.                 if(!fobj) //File not opened
  8.                 {
  9.                     cout<<"File cant open "<<endl;
  10.                     return 1;
  11.                 }
  12.  
  13.                 cout<<"<Date>"<<"\t\t<Name>"<<"\t<AccountNo>"<<"\t<AccountType>"<<"\t<TransType>"<<"\t<Amount>"<<endl;
  14.                 fobj>>timestamp>>name>>acc>>type>>trans>>amount;
  15.  
  16.                 while(fobj)
  17.                 {
  18.                     cout<<timestamp<<"\t"<<name<<"\t"<<acc<<"\t"<<type<<"\t\t"<<trans<<"\t\t"<<amount<<endl;
  19.  
  20.                     fobj>>timestamp>>name>>acc>>type>>trans>>amount;
  21.  
Expand|Select|Wrap|Line Numbers
  1. ofstream fobj;  //declare input file stream
  2.  
  3.     fobj.open("c:\\trans.txt",ios::app); //open file
  4.  
  5.  
  6.  
  7.         if(!fobj) //File not opened
  8.             {
  9.                 cout<<"File cant open "<<endl;
  10.                 return 1;
  11.             }
  12.  
  13.         else
  14.             {
  15.  
  16.                 fobj<<timestamp<<","<<name<<","<<acc<<","<<type<<","<<trans<<","<<amount<<endl;
  17.             }
  18.  
  19.  
  20.         fobj.close();  //close file
  21.  
i have created a file input but when i display it the output is not there what is the problem? when compiling it shows no error!!HELP!!

thanks in advance.
regrads
andrew
Feb 25 '07 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 1,510
it is not something as simple as a difference in file names? i.e. in current directory
Expand|Select|Wrap|Line Numbers
  1.         fobj.open("trans.txt"); //open file
  2.  
or in c:\
Expand|Select|Wrap|Line Numbers
  1.     fobj.open("c:\\trans.txt",ios::app); //open file
  2.  
Feb 25 '07 #2

P: 24
it is not something as simple as a difference in file names? i.e. in current directory
Expand|Select|Wrap|Line Numbers
  1.         fobj.open("trans.txt"); //open file
  2.  
or in c:\
Expand|Select|Wrap|Line Numbers
  1.     fobj.open("c:\\trans.txt",ios::app); //open file
  2.  
thanks for ya reply but its still the same no input!!here is a new program i created but dun know where the prob is: can anyone help?
Expand|Select|Wrap|Line Numbers
  1. case 1:
  2.             {
  3.  
  4.                 cout<<"This is the display of your transaction"<<endl;
  5.  
  6.                 ifstream fobj;  //declare input file stream
  7.  
  8.                 fobj.open("c:\\trans.txt"); //open file
  9.  
  10.                 if(!fobj) //File not opened
  11.                 {
  12.                     cout<<"File cant open "<<endl;
  13.                     return 1;
  14.                 }
  15.  
  16.                 cout<<"<Date>"<<"\t\t<Name>"<<"\t<AccountNo>"<<"\t<AccountType>"<<"\t<TransType>"<<"\t<Amount>"<<endl;
  17.                 fobj>>timestamp>>name>>acc>>type>>trans>>amount;
  18.  
  19.                 while(fobj)
  20.                 {
  21.                     cout<<timestamp<<"\t"<<name<<"\t"<<acc<<"\t"<<type<<"\t\t"<<trans<<"\t\t"<<amount<<endl;
  22.  
  23.                     fobj>>timestamp>>name>>acc>>type>>trans>>amount;
  24.  
  25.  
  26.                 }
  27.                 fobj.close();//close file
  28.  
  29.                 cout<<"Do you wish to go back to main menu?(y/n)"<<endl;
  30.                 cin>>back;
  31.                 if(back == 'y' || back == 'Y')
  32.                 {
  33.                     goto menu;
  34.                 }
  35.                 else if ( back == 'n' || back == 'N')
  36.                 {
  37.                     goto case0;
  38.                 }
  39.  
  40.             }
Expand|Select|Wrap|Line Numbers
  1.     ofstream fobj;  //declare input file stream
  2.  
  3.     fobj.open("c:\\trans.txt",ios::app); //open file
  4.  
  5.  
  6.  
  7.         if(!fobj) //File not opened
  8.             {
  9.                 cout<<"File cant open "<<endl;
  10.                 return 1;
  11.             }
  12.  
  13.         else
  14.             {
  15.  
  16.                 fobj<<timestamp<<","<<name<<","<<acc<<","<<type<<","<<trans<<","<<amount<<endl;
  17.             }
  18.  
  19.  
  20.         fobj.close();  //close file
  21.  
  22.         }//whole switch case
  23.  
here is the problem when i put c:\\trans.txt in the first code it does not print the cout command after dat but when i take off the c:\\ it prints. why is it like this? and i still can show the file dat i stored in a file i created? why is it like this can anyone help me?

thanks in advance
Feb 26 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.