cant find the prob!!HELP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • andrewanderson
    New Member
    • Jan 2007
    • 24

    cant find the prob!!HELP

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

    Code:
    	cout<<"This is the display of your transaction"<<endl;
    
    				ifstream fobj;  //declare input file stream
    
    				fobj.open("trans.txt"); //open file
    				
    				if(!fobj) //File not opened
    				{
    					cout<<"File cant open "<<endl;
    					return 1;
    				}
    
    				cout<<"<Date>"<<"\t\t<Name>"<<"\t<AccountNo>"<<"\t<AccountType>"<<"\t<TransType>"<<"\t<Amount>"<<endl;
    				fobj>>timestamp>>name>>acc>>type>>trans>>amount;
    
    				while(fobj)
    				{
    					cout<<timestamp<<"\t"<<name<<"\t"<<acc<<"\t"<<type<<"\t\t"<<trans<<"\t\t"<<amount<<endl;
    
    					fobj>>timestamp>>name>>acc>>type>>trans>>amount;
    Code:
    ofstream fobj;  //declare input file stream
    		
    	fobj.open("c:\\trans.txt",ios::app); //open file
    		
    		
    
    		if(!fobj) //File not opened
    			{
    				cout<<"File cant open "<<endl;
    				return 1;
    			}
    			
    		else
    			{
    			
    				fobj<<timestamp<<","<<name<<","<<acc<<","<<type<<","<<trans<<","<<amount<<endl;
    			}
    
    
    		fobj.close();  //close file
    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
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    it is not something as simple as a difference in file names? i.e. in current directory
    Code:
    		fobj.open("trans.txt"); //open file
    or in c:\
    Code:
    	fobj.open("c:\\trans.txt",ios::app); //open file

    Comment

    • andrewanderson
      New Member
      • Jan 2007
      • 24

      #3
      Originally posted by horace1
      it is not something as simple as a difference in file names? i.e. in current directory
      Code:
      		fobj.open("trans.txt"); //open file
      or in c:\
      Code:
      	fobj.open("c:\\trans.txt",ios::app); //open file
      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?
      Code:
      case 1:
      			{
      
      				cout<<"This is the display of your transaction"<<endl;
      
      				ifstream fobj;  //declare input file stream
      
      				fobj.open("c:\\trans.txt"); //open file
      				
      				if(!fobj) //File not opened
      				{
      					cout<<"File cant open "<<endl;
      					return 1;
      				}
      
      				cout<<"<Date>"<<"\t\t<Name>"<<"\t<AccountNo>"<<"\t<AccountType>"<<"\t<TransType>"<<"\t<Amount>"<<endl;
      				fobj>>timestamp>>name>>acc>>type>>trans>>amount;
      
      				while(fobj)
      				{
      					cout<<timestamp<<"\t"<<name<<"\t"<<acc<<"\t"<<type<<"\t\t"<<trans<<"\t\t"<<amount<<endl;
      
      					fobj>>timestamp>>name>>acc>>type>>trans>>amount;
      						
      						
      				}
      				fobj.close();//close file
      
      				cout<<"Do you wish to go back to main menu?(y/n)"<<endl;
      				cin>>back;
      				if(back == 'y' || back == 'Y')
      				{
      					goto menu;
      				}
      				else if ( back == 'n' || back == 'N')
      				{
      					goto case0;
      				}
      				
      			}
      Code:
      	ofstream fobj;  //declare input file stream
      		
      	fobj.open("c:\\trans.txt",ios::app); //open file
      		
      		
      
      		if(!fobj) //File not opened
      			{
      				cout<<"File cant open "<<endl;
      				return 1;
      			}
      			
      		else
      			{
      			
      				fobj<<timestamp<<","<<name<<","<<acc<<","<<type<<","<<trans<<","<<amount<<endl;
      			}
      
      
      		fobj.close();  //close file
      
      		}//whole switch case
      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

      Comment

      Working...