error C2297: '>>' : illegal, right operand has type 'void'
error C2296: '>>' : illegal, left operand has type 'float'
error C2297: '>>' : illegal, right operand has type 'void'
warning C4552: '>>' : operator has no effect; expected operator with side-effect.
i get these errors and i dont know why when input and outputing a file.

#include<iostream>
#include<fstream>
#include<cstdlib>
#include<iomanip>
using namespace std;
void main()
{
	
	float price,curr_total=0.0;
	int itemnum, wrong=0, items;    
	ifstream in_stream;
	ofstream in_stream1;
    ifstream in_stream2;
	ofstream in_stream3;	
	ifstream in_stream4;
	ofstream in_stream5;
	in_stream2.open("pricelist.txt");
	in_stream4.open("receipt.txt");
	in_stream.open("itemlist.txt"); // list of avaliable items 

in_stream1.open("items.txt", ios::out);
// list of avaliable items and there prices.
        while((! in_stream.eof()) && (! in_stream2.eof())) 
// reads in_stream and in_stream2 
                   //until the end of file
        {
			itemnum >> in_stream.open("itemlist.txt", ios::in);
 // i need to get the items list
                         //which is in this file and check 
                     // to see if item is in item list
			 price >> in_stream2.open("pricelist.txt", ios::in);
 // opens pricelist.txt
				while( in_stream2 >> itemnum >> price )
				{
	while((price== (price*1.00)) && (itemnum==    itemnum*1)))
// if price equals a double than its a price 
						                                                    // itemnum = whole number.
					{
			cout << itemnum << ' ' << price << '\n';
 // gets item number and price
						itemnum++;                            
   // saves item numbers and counts it
						price++;            
                     // saves price and counts
						curr_total= price++;
                        cout << curr_total;
						{
				in_stream4.open("receipt.txt", ios::in);
 // sends items and prices to receipt.txt 
						{
	in_stream5.open("display.txt", ios::out);
	in_stream5 << setw(5) << "Item number " << setw(5) << " Price " << setw(5) << " Total " << endl;
in_stream5 << " ---------------------------- " << endl;
   in_stream5 << setw(5) << itemnum++ << setw(5) << price++ << setw(5) << curr_total << endl;
	in_stream5 << " You have a total of " << wrong++ << " errors " << endl;
	while((price!= (price*1.00)) || (itemnum != (itemnum*1)))
	// if price ! = 2 double and itemnum != whole num
							{
						cout << " error " << endl;
	       				     wrong++; 
 // keeps track of errors so i can display them after program has run
							}
						}
						}

					}
				}
		}
    in_stream.close(); // closing files.
	in_stream1.close();
	in_stream2.close();
	in_stream3.close();
	in_stream4.close();
	in_stream5.close();
	system("pause");
}

Edited 6 Years Ago by peter_budo: Correcting code tags, please do not use nested code tags

Comments
For 100+ posts, you really ought to do better with the code tags - what a horrible mess - join the end of the ignore queue

IM HAVING PROBLEMS WITH THESE TWO LINES. AND I HAVE A QUESTION BOUT FORMATING THIS PROGRAM CORRECTLY OR NOT. I AM NEW AT C++ SO COULD SOMEONE TELL ME IF AM MEETING THE ASSIGNMENT OR DO I NEED TO THROW THIS PROGRAM AWAY AND START OVER? I BELIEVE THIS IS CORRECT EXCEPT FOR THE COUPLE ERRORS.
WAT I HAVE 2 DO (BELOW)
process a list of items purchased and write a receipt showing the total cost of the items in the list. "itemlist.txt". This file contains the inventory numbers . A second file, called "pricelist.txt" contains a list of items (stored as inventory numbers) and their respective prices. You must also create an output file called “receipt.txt” that contains a header and the receipt data .
ERROR LINES (BELOW)

in_stream1.open("items.txt", ios::out);
// list of avaliable items and there prices.
        while((! in_stream.eof()) && (! in_stream2.eof())) 
// reads in_stream and in_stream2 
                   //until the end of file
        {
            itemnum >> in_stream.open("itemlist.txt", ios::in); HERE
 // i need to get the items list
                         //which is in this file and check 
                     // to see if item is in item list
             price >> in_stream2.open("pricelist.txt", ios::in); HERE
 // opens pricelist.txt
                while( in_stream2 >> itemnum >> price )
                {
    while((price== (price*1.00)) && (itemnum==    itemnum*1)))
// if price equals a double than its a price 
                                                                            // itemnum = whole number.
                    {
            cout << itemnum << ' ' << price << '\n';
 // gets item number and price
                        itemnum++;                            
   // saves item numbers and counts it
                        price++;            
                     // saves price and counts
                        curr_total= price++;
                        cout << curr_total;
                        {
                in_stream4.open("receipt.txt", ios::in);
 // sends items and prices to receipt.txt 
                        {
    in_stream5.open("display.txt", ios::out);

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Comments
I really couldn't give a toss for anyone who YELLS LIKE AN IDIOT and after 100 posts still can't use code tags

I think you are a little confused about how to do file i/o. First you have to open the file, next check if the file open succeeded, and finally read the file

in_stream.open("itemlist.txt", ios::in);
if( !in_stream.is_open() )
{
   cout << "Error opening the file\n";
   return 1;
}
// now you are ready to read the file
// read each item in the file
while( in_stream >> itemnum >> price)
{
   // blabla
}
Comments
Nice, but I fear the situation is a hopeless case.

do i have to file and check than read each time like so:

ifstream in_stream; // opens itemlist.txt
ofstream in_stream1; // reads in items.txt
ifstream in_stream2; // opens pricelist.txt
ofstream in_stream3;//	reads in plist.txt
ifstream in_stream4;// opens recipt.txt
ofstream in_stream5;// opens display.txt

in_stream.open("itemlist.txt"); // list of avaliable items
  if( !in_stream.is_open() )// check to see if itemlist.txt is open
   {
   cout << "Error opening the file\n" << endl;
  exit(1);
   }
   in_stream1.open("items.txt");
   if( !in_stream1.is_open() )// check to see if itemlist.txt is open
    {
      cout << "Error opening the file\n";
     exit(1);
      }
    in_stream2.open("pricelist.txt");
    if( !in_stream2.is_open() )
    {
     cout << "Error opening the file\n";
     exit (1);
    }

     in_stream3.open("plist.txt");
     if( !in_stream3.is_open() )
       {
	cout << "Error opening the file\n";
	exit (1);
	}
	
     in_stream4.open("recipt.txt");
	if( !in_stream4.is_open() )
	{
	  cout << "Error opening the file\n";
	  exit (1);
	  }

    in_stream5.open("display.txt");
    if( !in_stream5.is_open() )
	{
	 cout << "Error opening the file\n";
	exit (1);
	}

  float price,curr_total=0.0;
  int itemnum, wrong=0; 
	
  while((! in_stream.eof()) && (! in_stream2.eof())) // reads in_stream and in_stream2 
   //until the end of file
        {
		 in_stream >> itemnum; // i need to get the items list
		                                           //which is in this file and check 
		                                             // to see if item is in item list
		 in_stream2 >> price ; // opens pricelist.txt
		 in_stream3 << itemnum << price;
				{
while((price== (price*1.00)) && (itemnum == (itemnum*1)))
// if price equals a double than its a price 
                                              // itemnum = whole number.
					{
in_stream3 << itemnum << ' ' << price << '\n';
 // gets item number and price
			itemnum++;   // saves item numbers and counts it
		     		price++;   // saves price and counts
	    			curr_total= price++;
                    cout << curr_total;
						
	in_stream4 >> itemnum >> price >> curr_total; 
// sends items and prices to receipt.txt 
																					
in_stream5 << setw(5) << "Item number " << setw(5) << " Price " << setw(5) << " Total " << endl;

the problem i am having still is writing to the file i believe its that. i can open the files outside of my program but nothing is in there and am i reading and writing to these files correctly meaning can i write code this way?

Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

This article has been dead for over six months. Start a new discussion instead.