I appreciate people are busy seeing that the knowleadgeable ones are being inundated with queries from left to right...
However, if will be very well appreciated if someone respond to this please.
Anyway, I have taken the liberty to read the file using 'ifstream' as i thought perhaps i am not supposed to manually open the *txt file i wrote to the directory (please advise if my understanding is wrong)?
To add insult to injury my new read code is producing below errors (please note, these codes are only part of my main program):
--------------------Configuration: Menu - Win32 Debug--------------------
Compiling...
Menu.cpp
C:\Documents and Settings\Owner\My Documents\My Projects\Menu\Menu.cpp(98) : error C2248: 'init' : cannot access protected member declared in class 'std::basic_ios<char,struct std::char_traits<char> >'
c:\program files\microsoft visual studio\vc98\include\ios(79) : see declaration of 'init'
C:\Documents and Settings\Owner\My Documents\My Projects\Menu\Menu.cpp(98) : error C2664: 'void __thiscall std::basic_ifstream<char,struct std::char_traits<char> >::open(const char *,int)' : cannot convert parameter 2 from 'void (__thiscall std::bas
ic_ios<char,struct std::char_traits<char> >::*' to 'int'
Conversion is a valid standard conversion, which can be performed implicitly or by use of static_cast, C-style cast or function-style cast
Error executing cl.exe.
Menu.obj - 2 error(s), 0 warning(s)
--------------------------------------------------------------------------------------------------
This is my read file code (please note it is in a different function to the write code as the overall project is a menu call, i hope this information helps)...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
{
short Item, price;
char YourName [25];
ifstream * FileTo;
FileTo = new ifstream();
if (FileTo==NULL)
{
cerr<<"Cannot create file on Heap\n";
}
FileTo->open("My_Cplusplus_File.bin", ios::init);
if (FileTo->bad!=0)
{
cerr<<"Error opening file\n";
}
FileTo->read((char *)&Item, sizeof(Item));
FileTo->read((char *)&price, sizeof(price));
FileTo->read(YourName, 25);
while (FileTo->eof()==0)
{
if(Item>75)
{
cout<<"Item:"<<Item<<"is greater than 75\n";
}
FileTo->read((char *)&Item, sizeof(Item));
FileTo->read((char *)&price, sizeof(price));
FileTo->read(YourName, 25);
}
FileTo->close();
delete FileTo;
}
|