Hey. I'm trying to create part of a program that will read data from a text file, store the data into variables and then write the data into a random access file. So far this is what I have.
#include <iostream>
using namespace std;
#include <conio.h>
#include <fstream> //file stream
using std::fstream;
struct mealItem
{
int idNo; //meal ID number
char name[22]; //name of meal
double unitCost; //unit cost of meal
char descrip[55]; //description of meal
};
typedef struct mealItem item;
int main()
{
item meal; //meal of structure type item
fstream inFile("Meals.dat", ios::in); //text file
fstream outFile("Inventory.dat", ios::out, ios::binary); //RAF file
while(!inFile.eof())
{
inFile >> meal.idNo;
inFile.getline (meal.name, 22, ",");
inFile.ignore();
inFile >> meal.unitCost;
inFile.getline (meal.descrip, 55, ".");
inFile.ignore();
cout << meal.idNo << "\t" << meal.unitCost << "\n";
outFile.seekp((meal.idNo - 100) * sizeof(item));
outFile.write(reinterpret_cast<char*> (&meal), sizeof(item));
} //endwhile
inFile.close();
outFile.close();
getch();
return 0;
} //end of main program
But when I go to compile the program, I'm getting this error..
[quote]
error C2664: 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::getline(_Elem *,std::streamsize,_Elem)' : cannot convert parameter 3 from 'const char [2]' to 'char'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
There is no context in which this conversion is possible
[/quote]
Any help with this would be most appreciated.