Error: Declaration Syntax error on function input
Note: using turbo c++ 4.5 compiler

#include "iostream.h"
#include "conio.h"
#include "stdlib.h"
#include "cstring.h"
#include "fstream.h"
#include "time.h"
#include "stdio.h"
time_t now=time(0);char*dt=ctime(&now);

int ch,dn=0;
struct BuyerInfo
{
 char id[5];
 string fn;
 string mn;
 string ln;
 string ad;
}
 info[100];
struct grocery
{
char barcode[5];
string prodname;
string category;
float price;
} ;

void inputs()
{
 cout<< "\n================================================================================";
 cout<< "\t\t\n\t\t  Please fill in the following required information\n";
 cout<< "\n================================================================================";
char ans='y';
    while (ans=='y'||ans=='Y')
    {
        cout<< "\nBuyer's ID:B";
        for(dn=0;dn<1;dn++)
        {
         cin>>info[dn].id;
        }
            strcat(info[dn].id,".docx");
            FILE * pFile;
            pFile=fopen (info[dn].id,"rb");
                if(pFile!=NULL)
                {
                    cout<<" ID NUMBER IS IN USED"<<endl;
                    cout<<" DO YOU WANT TO ENTER ANOTHER?(Y/N) ";
                    cin>>ans;
                    clrscr();
                    if( ans=='n'||ans=='N')_exit(0);
                }
            else
                {
                FILE * mFile;
                mFile=fopen (info[dn].id,"w");
                fclose (mFile);ans='?';
                    for(dn=0;dn<1;dn++)
                    {
                    cout<< "Enter First Name:";
                    getline(cin,info[dn].fn);
                    cout<< "Enter Middle Name:";
                    getline(cin,info[dn].mn);
                    cout<< "Enter Last Name:";
                    getline(cin,info[dn].ln);
                    cout<< "Enter Address:";
                    getline(cin,info[dn].ad);
                    gotoxy(2,11);
                    cout<<"Date: "<<dt;
                    }
                }
            }

void mainscreen()
    {
    cout<< "\n================================================================================";
    cout<< "\t\t\t         VONGOLA POINT OF SALE SYSTEM";
    cout<< "\n================================================================================";
    cout<< "\nPlease choose from the following:";
    cout<< "\n[1]Scan Buyer's Items";
    cout<< "\n[2]Additional Items";
    cout<< "\n[3]Cancel Items";
    cout<< "\n[4]Searching for Buyer's Record";
    cout<< "\n[5]Deleting Buyer's Record";
    cout<< "\n[6]Show all Products available in the Grocery Store";
    cout<< "\n[7]Show Products based on Product Category";
    cout<< "\n[8]Exit";
    cout<< "\n================================================================================";
    cout<< "\nOption:";
    cin>>ch;
    }

int main()
{
grocery data[50];
ifstream in;
in.open("grocery.txt");
for(int i = 0;i<50; i++)
{
in >>data[i].barcode >> data[i].prodname >> data[i].category >> data[i].price;
}
in.close();
}
return 0;

inputs();
clrscr();
mainscreen();
    switch(ch)
        {
    case '1':break;
    case '2':break;
    case '3':break;
    case '4':break;
    case '5':break;
    case '6':break;
    case '7':break;
    case '8':break;
    default:_exit(0);
        }
    }

It would be much easier if you posted the line on which the syntax error occured, if it is possible anyway.

However, the problem I see is with line 99:

in >>data[i].barcode >> data[i].prodname >> data[i].category >> data[i].price;

The member variables 'prodname' and 'category' of type std::string but you're trying to use the overloaded shift-right operator '>>' with the file stream 'ifstream'. The problem is, there is no overloaded version that handles std::string variables.

You can check the list of available functions and parameters with '>>' here:
www.cplusplus.com/reference/iostream/istream/operator>>/ (just copy and paste)

There is no such thing as istream& operator>> (istream& is, std::string& str);

You have to use the std::string compatible versions to extract a std::string from a stream.
istream& getline ( istream& is, string& str, char delim );
istream& getline ( istream& is, string& str );
http://www.cplusplus.com/reference/string/getline/

And on line 103 you have return 0; so whatever code follows never get executed.

Edited 4 Years Ago by dx9_programmer

Line 74 is an open brace in void mainscreen().

You obviously haven't learned how to format your code yet. Please take a look at this and format your code properly so it can be followed. Many errors can be found in seconds with properly formatted code.

This question has already been answered. Start a new discussion instead.