#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char ch;
ofstream outf("ITEM.txt");
cout << "Enter item: ";
char name[30];
cin >> name;
outf << name << "\n";
cout << "Enter item cost: ";
float cost;
cin >> cost;
outf << cost;
cout << "written to file item.txt\n";
outf.close();
ifstream inf("ITEM.txt");
cout << "current location of pointer: " << inf.tellg() << endl;
inf.seekg(0);
while(!inf.eof())
{
inf.get(ch);
cout << ch;
}
cout << "\nreads from file item.txt";
inf.close();
cin.ignore(numeric_limits< streamsize >::max(),'\n');
cin.get();
return 0;
}
can you tell me why do i get a wrong output when I try to read the file created
ouput is like :
Enter item: soap
Enter item cost: 25
written to file item.txt
soap
255 //I am getting an extra 5 here.why?
reads from file item.txt