Ok , Thanks! I will Change that one , So even Data member " Brand " will also be a string then , Right? But i still dont know whats wrong with the getline , Someone help me out with that.
#include<iostream.h>
#include<fstream.h>
#include<string.h>
int size=2;
class Listing
{
public:
string name;
int price;
string brand;
int displacement;
int power;
int category;
Listing()
{
price=0;
brand=0;
displacement=0;
power=0;
category=0;
}
};
int main()
{
int i;
Listing bikes[10];
string input;
fstream datafile;
datafile.open("Bikes.txt",ios::in);
if(datafile.is_open())
{
for(i=0;i<size;i++)
{
if(datafile.good())
{
getline(datafile,input,"$");
bikes[i].name=input;
getline<datafile,input,"$">;
bikes[i].price=input;
getline<datafile,input,"$">;
bikes[i].brand = input;
getline<datafile,input,"$">;
bikes[i].displacement = input;
getline<datafile,input,"$">;
bikes[i].power = input;
getline<datafile,input,"$">;
bikes[i].category = input;
cout<<bikes[i].name<<endl<<bikes[i].price<<endl<<bikes[i].brand<<endl<<bikes[i].displacement<<endl<<bikes[i].power<<endl<<bikes[i].category<<endl;
}
}
}
Even then im getting the error that , getline function must have function prototype....
Line 30: I am just using 2 as a example because bikes.txt which i wrote above only had 2 bikes in it so only.
Lines 35 - 45 : I reliazed that and i corrected it , Yet i have the same error.
Abstractionanon , Did i declare my string properly because im using a DOSbox C++ complier which is showing an error that , Typename expected error. Is there something wrong with the declaration?
And Even Is_open() has an error that , it doesnt belong to fstream.
Is this a compiler problem? Should i change to any Linux Distro with C++ essentials?