严重错误C1075:在左括号之前发现文件结尾,并且读写文件不起作用 [英] fatal error C1075: end of file found before the left brace and read and write files not working

查看:184
本文介绍了严重错误C1075:在左括号之前发现文件结尾,并且读写文件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人还能告诉我评论中陈述的我要执行的操作是否正确.我是c ++的新手,我认为它是正确的,但我对此表示怀疑

could someone also tell me if the actions i am attempting to do which are stated in the comments are correct or not. i am new at c++ and i think its correct but i have doubts

#include<iostream>
#include<fstream>
#include<cstdlib>
#include<iomanip>
using namespace std;
int main()
{
 ifstream in_stream; // reads itemlist.txt
 ofstream out_stream1; // writes in items.txt
    ifstream in_stream2; // reads pricelist.txt
 ofstream out_stream3;// writes in plist.txt
 ifstream in_stream4;// read recipt.txt
 ofstream out_stream5;// write display.txt
 float price='  ',curr_total=0.0;
 int wrong=0;
 int itemnum='  ';
 char next;
 in_stream.open("ITEMLIST.txt", ios::in); // list of avaliable items
   if( in_stream.fail() )// check to see if itemlist.txt is open
   {
       wrong++;
      cout << " the error occured here0, you have " << wrong++ << " errors"  << endl;
      cout << "Error opening the file\n" << endl;
      exit(1);
      }
   else{
    cout << " System ran correctly " << endl;

 out_stream1.open("listWititems.txt", ios::out); // list of avaliable items
   if(out_stream1.fail() )// check to see if itemlist.txt is open
   {
       wrong++;
      cout << " the error occured here1, you have " << wrong++ << " errors"  << endl;
      cout << "Error opening the file\n";
      exit(1);
      }
   else{
    cout << " System ran correctly " << endl;
   }

 in_stream2.open("PRICELIST.txt", ios::in);    
  if( in_stream2.fail() )
   {
       wrong++;
      cout << " the error occured here2, you have " << wrong++ << " errors"  << endl;
      cout << "Error opening the file\n";
      exit (1);
   }
   else{
    cout << " System ran correctly " << endl;
   }

 out_stream3.open("listWitdollars.txt", ios::out);    
  if(out_stream3.fail() )
   {
      wrong++;
      cout << " the error occured here3, you have " << wrong++ << " errors"  << endl;
      cout << "Error opening the file\n";
      exit (1);
   }
   else{
    cout << " System ran correctly " << endl;
   }

 in_stream4.open("display.txt", ios::in);
  if( in_stream4.fail() )
   {
       wrong++;
      cout << " the error occured here4, you have " << wrong++ << " errors"  << endl;
      cout << "Error opening the file\n";
      exit (1);
   }
   else{
    cout << " System ran correctly " << endl;
   }


 out_stream5.open("showitems.txt", ios::out);
   if( out_stream5.fail() )
   {
       wrong++;
      cout << " the error occured here5, you have " << wrong++ << " errors"  << endl;
      cout << "Error opening the file\n";
      exit (1);
   }
   else{
    cout << " System ran correctly " << endl;
   }
    in_stream.close(); // closing files.
  out_stream1.close();
  in_stream2.close();
  out_stream3.close();
  in_stream4.close();
  out_stream5.close();
  system("pause");
 in_stream.setf(ios::fixed);
 while(in_stream.eof())
 {
  in_stream >> itemnum;
  cin.clear();
  cin >> next;
 }
 out_stream1.setf(ios::fixed);
 while (out_stream1.eof())
 {
  out_stream1 << itemnum;
  cin.clear();
  cin >> next;
 }
 in_stream2.setf(ios::fixed);
 in_stream2.setf(ios::showpoint);
 in_stream2.precision(2);
    while((price== (price*1.00)) && (itemnum == (itemnum*1)))
   {
    while (in_stream2 >> itemnum >> price) // gets itemnum and price
    {
     while (in_stream2.eof())  // reads file to end of file
     {
     in_stream2 >> itemnum;
    in_stream2 >> price;
    price++;
    curr_total= price++;
    in_stream2 >> curr_total;
    cin.clear();  // allows more reading
    cin >> next;
    }

   }
  }
 out_stream3.setf(ios::fixed);
 out_stream3.setf(ios::showpoint);
 out_stream3.precision(2);
 while((price== (price*1.00)) && (itemnum == (itemnum*1)))
  {
   while (out_stream3 << itemnum << price)
    {
     while (out_stream3.eof())  // reads file to end of file
     {
     out_stream3 << itemnum;
     out_stream3 << price;
     price++;
     curr_total= price++;
     out_stream3 << curr_total;
     cin.clear();  // allows more reading
     cin >> next;
     }
    return itemnum, price;
   }
  }
 in_stream4.setf(ios::fixed);
 in_stream4.setf(ios::showpoint);
 in_stream4.precision(2);
 while ( in_stream4.eof())
 {
  in_stream4 >> itemnum >> price >> curr_total;
  cin.clear();
  cin >> next;
 }
 out_stream5.setf(ios::fixed);
 out_stream5.setf(ios::showpoint);
 out_stream5.precision(2);
 out_stream5 <<setw(5)<< " itemnum " <<setw(5)<<" price "<<setw(5)<<" curr_total " <<endl; // sends items and prices to receipt.txt 
 out_stream5 << setw(5) <<  itemnum << setw(5) <<price << setw(5)<< curr_total; // sends items and prices to receipt.txt 
 out_stream5 << " You have a total of " << wrong++ << " errors " << endl; 


}

推荐答案

我很可能会猜测您在其他else块中缺少'}'.

I'd hazard a guess you're missing '}' in first else block.

为避免将来出现此类问题,请修复缩进(或让AStyle或类似程序为您修复),并使用突出显示语法的编辑器(尤其是括号之间的代码块).

To avoid such problems in the future, fix your indentation (or let AStyle or similar program fix it for you) and use editor that highlights the syntax (especially blocks of code between braces).

这篇关于严重错误C1075:在左括号之前发现文件结尾,并且读写文件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆