I/O problems.

This is a discussion on I/O problems. within the C++ Programming forums, part of the General Programming Boards category; I was wondering what Im doin wrong with this code, I keep getting errors like, "error C2297: '>>' : illegal, ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    16

    Question I/O problems.

    I was wondering what Im doin wrong with this code, I keep getting errors like, "error C2297: '>>' : illegal, right operand has type 'float' ".

    Code:
    // Ebay Business organizer.cpp : Defines the entry point for the console application.
    //
    
    #include <fstream> // header files
    #include "stdafx.h"
    #include <iostream>	
    
    using namespace std;
    
    //start of functions
    void addrecord();
    void findtotal();
    
    //globals
    float temp_data;
    float multa;
    float multb;
    		
    int main()                        
    {
      int input;
      start:
    
      cout<<" Welcome to the ebay business or seller's organizer! " <<endl;
      cout<<"---------------------------------------------------------------------------"<<endl;
      cout<<"1. Add a new record; the item number, quanity, price, to the database. "<<endl;
    
      cin>> input;
    
      switch ( input ) {
      
      case 1:
      addrecord();
        
    
       
      
    
      }
    
    cin.get();
    
    return 0;
    
    }
    
    void addrecord()
    {
    	
    	  ofstream add_record ( "db.txt", ios::app );
    
          cout<<"---------------------------------------------------------------------------"<<endl;
    	  cout<<"Enter the item number:"<<endl;
    	  cin>>temp_data;
    	  cout<<"Processing data..."<<endl;
    	  temp_data>>add_record;
    
    	  cout<<"Enter item quanity:"<<endl;
    	  cin>>temp_data;
    	  temp_data>>multa;
    	  cout<<"Processing data..."<<endl;
    	  temp_data>>add_record;
    
    	  cout<<"Enter item price:"<<endl;
    	  cin>>temp_data;
    	  temp_data>>multb;
    	  cout<<"Processing data..."<<endl;
    	  temp_data>>add_record;
    
    	  cout<<"Enter item name:"<<endl;
    	  cin>>temp_data;
    	  cout<<"Processing data..."<<endl;
    	  temp_data>>add_record;
    
    	  temp_data = multa * multb;
    	  temp_data>>add_record;
    
    	  cin.ignore();
    	  cout<<"Item added to db."<<endl;
    	  goto start;
    
    
    }
    Im a beginner.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >temp_data>>add_record;
    Other way around. The stream goes on the left and the variable goes on the right:
    Code:
    add_record>>temp_data;
    Repeat until the error goes away.
    My best code is written with the delete key.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,799
    add_record is an ofstream object so unless I'm mistaken that would be:

    Code:
    add_record << temp_data;
    and not:

    Code:
    add_record >> temp_data;
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    So it is. And now that I look more closely, I see the >> operator being used with a float on both sides. Perhaps the OP should read the first few chapters of a book on C++ before going any further.
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    16
    Well, I did all that you told me too and I have even more errors, let me post them. I don't have a book, Im basicly learning off tutorials, I do have a DirectX and game programming book that has helped me with adding graphics, etc. but I wanted to make just a simple inventory management system for fun. Seems like I dont know as much as I thought.

    Errors:
    Code:
    --------------------Configuration: Ebay Business organizer - Win32 Debug--------------------
    Compiling...
    Ebay Business organizer.cpp
    C:\Documents and Settings\Paul \My Documents\C++ programming\Inventory\Ebay Business organizer\Ebay Business organizer.cpp(22) : warning C4102: 'start' : unreferenced label
    C:\Documents and Settings\Paul \My Documents\C++ programming\Inventory\Ebay Business organizer\Ebay Business organizer.cpp(50) : error C2079: 'add_record' uses undefined class 'basic_ofstream<char,struct std::char_traits<char> >'
    C:\Documents and Settings\Paul \My Documents\C++ programming\Inventory\Ebay Business organizer\Ebay Business organizer.cpp(50) : error C2078: too many initializers
    C:\Documents and Settings\Paul \My Documents\C++ programming\Inventory\Ebay Business organizer\Ebay Business organizer.cpp(56) : error C2296: '<<' : illegal, left operand has type 'float'
    C:\Documents and Settings\Paul \My Documents\C++ programming\Inventory\Ebay Business organizer\Ebay Business organizer.cpp(56) : error C2297: '<<' : illegal, right operand has type 'float'
    C:\Documents and Settings\Paul \My Documents\C++ programming\Inventory\Ebay Business organizer\Ebay Business organizer.cpp(60) : error C2296: '>>' : illegal, left operand has type 'float'
    C:\Documents and Settings\Paul \My Documents\C++ programming\Inventory\Ebay Business organizer\Ebay Business organizer.cpp(60) : error C2297: '>>' : illegal, right operand has type 'float'
    C:\Documents and Settings\Paul \My Documents\C++ programming\Inventory\Ebay Business organizer\Ebay Business organizer.cpp(62) : error C2296: '<<' : illegal, left operand has type 'float'
    C:\Documents and Settings\Paul \My Documents\C++ programming\Inventory\Ebay Business organizer\Ebay Business organizer.cpp(62) : error C2297: '<<' : illegal, right operand has type 'float'
    C:\Documents and Settings\Paul \My Documents\C++ programming\Inventory\Ebay Business organizer\Ebay Business organizer.cpp(66) : error C2296: '>>' : illegal, left operand has type 'float'
    C:\Documents and Settings\Paul \My Documents\C++ programming\Inventory\Ebay Business organizer\Ebay Business organizer.cpp(66) : error C2297: '>>' : illegal, right operand has type 'float'
    C:\Documents and Settings\Paul \My Documents\C++ programming\Inventory\Ebay Business organizer\Ebay Business organizer.cpp(68) : error C2296: '<<' : illegal, left operand has type 'float'
    C:\Documents and Settings\Paul \My Documents\C++ programming\Inventory\Ebay Business organizer\Ebay Business organizer.cpp(68) : error C2297: '<<' : illegal, right operand has type 'float'
    C:\Documents and Settings\Paul \My Documents\C++ programming\Inventory\Ebay Business organizer\Ebay Business organizer.cpp(73) : error C2296: '<<' : illegal, left operand has type 'float'
    C:\Documents and Settings\Paul \My Documents\C++ programming\Inventory\Ebay Business organizer\Ebay Business organizer.cpp(73) : error C2297: '<<' : illegal, right operand has type 'float'
    C:\Documents and Settings\Paul \My Documents\C++ programming\Inventory\Ebay Business organizer\Ebay Business organizer.cpp(76) : error C2296: '<<' : illegal, left operand has type 'float'
    C:\Documents and Settings\Paul\My Documents\C++ programming\Inventory\Ebay Business organizer\Ebay Business organizer.cpp(76) : error C2297: '<<' : illegal, right operand has type 'float'
    Error executing cl.exe.
    
    Ebay Business organizer.exe - 16 error(s), 1 warning(s)

  6. #6
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,799
    Well, you said you've made some changes and provided a list of errors. How about showing us the modified code.

    Quote Originally Posted by Skynet-systems
    Well, I did all that you told me too and I have even more errors,
    Don't let that discourage you or lull you into thinking the direction you are headed is the wrong one. If it is what I think it is, I'm willing to bet that all those errors from line 56 on down are all due to what is happening on line 50. That is, fix line 50 and it is quite possible all those other errors may go away. Sometimes fixing things may cause more errors to pop up than an earlier version of your code. That does not mean you should necessarily go back to the way things were. It may simply mean that now that you've fixed some errors, the compiler is able to recognize further problems that were also already in your code but were hidden due to the earlier errors.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    16
    Hrmm, I don't quite understand whats wrong with line 50. Im pretty sure im creating the append instance correctly.

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > temp_data>>multa;
    > temp_data>>multb;
    These are float variables, so you should use the assignment operator here:
    multa = temp_data;
    multb = temp_data;

  9. #9
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,799
    Quote Originally Posted by Skynet-systems
    Hrmm, I don't quite understand whats wrong with line 50. Im pretty sure im creating the append instance correctly.

    We do not posses the ability to remote view like those CIA psychics... we cannot comment on your current code unless you post it.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  10. #10
    Registered User
    Join Date
    Jan 2005
    Posts
    16
    The code is posted above...... The entire code.
    Here it is again:
    Code:
    // Ebay Business organizer.cpp : Defines the entry point for the console application.
    //
    
    #include <fstream> // header files
    #include "stdafx.h"
    #include <iostream>	
    
    using namespace std;
    
    //start of functions
    void addrecord();
    void findtotal();
    
    //globals
    float temp_data;
    float multa;
    float multb;
    		
    int main()                        
    {
      int input;
      start:
    
      cout<<" Welcome to the ebay business or seller's organizer! " <<endl;
      cout<<"---------------------------------------------------------------------------"<<endl;
      cout<<"1. Add a new record; the item number, quanity, price, to the database. "<<endl;
    
      cin>> input;
    
      switch ( input ) {
      
      case 1:
      addrecord();
        
    
       
      
    
      }
    
    cin.get();
    
    return 0;
    
    }
    
    void addrecord()
    {
    	
    ofstream add_record( "db.txt", ios::app );
    
    
          cout<<"---------------------------------------------------------------------------"<<endl;
    	  cout<<"Enter the item number:"<<endl;
    	  cin>>temp_data;
    	  cout<<"Processing data..."<<endl;
          add_record << temp_data;;
    
    	  cout<<"Enter item quanity:"<<endl;
    	  cin>>temp_data;
          multa = temp_data;
    	  cout<<"Processing data..."<<endl;
          add_record << temp_data;
    
    	  cout<<"Enter item price:"<<endl;
    	  cin>>temp_data;
    	  multb = temp_data;
    	  cout<<"Processing data..."<<endl;
          add_record << temp_data;
    
    	  cout<<"Enter item name:"<<endl;
    	  cin>>temp_data;
    	  cout<<"Processing data..."<<endl;
          add_record << temp_data;
    
    	  temp_data = multa * multb;
          add_record << temp_data;
    
    	  cin.ignore();
    	  cout<<"Item added to db."<<endl;
    	  goto start;
    
    
    }

  11. #11
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Ignoring the fact that you're trying to use goto in a manner that could easily be implemented with a loop, goto only words within the same function. You can't jump between functions with it.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. silly file I/O problems.
    By n3v in forum C++ Programming
    Replies: 4
    Last Post: 06-19-2007, 06:40 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 05:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 04:48 PM
  4. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  5. file i/o and plain old bad luck
    By rokenrol in forum C Programming
    Replies: 7
    Last Post: 07-09-2006, 02:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21