#include<iostream>
#include<cstdlib>
#include<fstream>
using namespace std;

int main()
{
	
	float x;
	int i=0;
	fstream editFile("myNums.txt", ios::in|ios::out);
	if(!editFile)
	{
		cout<<"\nUnable to open myNums.txt.";
		exit(1);
	}


	
	
	editFile.read(reinterpret_cast<char *>(&x),sizeof(float));
	
	while(editFile && !editFile.eof())
	{
	cout<<i++<<":"<<x<<" ";
	editFile.read(reinterpret_cast<char *>(&x),sizeof(float));
	}
	editFile.clear();

	cout<<"\nEnter the index of the float to change: ";
	cin>>i;
	editFile.seekg(i*sizeof(float));
	editFile.read(reinterpret_cast<char *>(&x),sizeof(float));
	
	/* Echo the chosen value. */
	cout<<"\nThat's "<<x<<".\n";
	cout<<"Enter the new value of the float: ";
	cin>>x;
	editFile.seekp(i*sizeof(float));//pointer positioning for writing
	editFile.write(reinterpret_cast<char *>(&x),sizeof(float));

	editFile.seekg(0);//pointer positioning for reading
	i=0;

	editFile.read(reinterpret_cast<char *>(&x),sizeof(float));
	while(editFile && !editFile.eof())
	{
	cout<<i++<<":"<<x<<" ";
	editFile.read(reinterpret_cast<char *>(&x),sizeof(float));
	}
	
	editFile.close();
		
	return 0;
}
