is it allowed to read and write in the same time for the same file ?

I do want to open file ,read data , anlyze the input and modify some thing in the same file,contains string and integers, and close in the last.
the function works to read file , modify a specific value :

1
2
3
4
5
6
7
8
9
int store::print(fstream& Myfile)
{
	unsigned req_quantity , req_num ;
	int response = 0 ;

	cout << " Please Enter the Item Number \n" << endl;
	cin >> req_num;

	cou
t << " Please Enter the required quantity \n" << endl;
cin >> req_quantity;

Myfile.open("items.txt");
if(Myfile.is_open())
while(! Myfile.eof())
{

Myfile >> item_num ;
getline (Myfile, item_name);

Myfile >> quantity ;
Myfile >> v_point;
getline ( Myfile , item_P_company );
Myfile >> item_ypro;
//Myfile.ignore();


if( item_num == req_num )
{
response = 1;
if((quantity - req_quantity) >= v_point)
{

quantity-=req_quantity;
Myfile << quantity;
paste_data(Myfile);
}
else

{
cout << " There is no enough quantity of " << item_name <<endl;
paste_data(Myfile);
}
}

else
{
response = 0;

paste_data(Myfile);
}



}

else
{
cerr << " the file is not opened " <<endl;
exit(1);
}
Myfile.close();
return response;
}

void store::paste_data(fstream& OutFile)
{
OutFile<< item_num << endl;
OutFile << item_name <<endl;

OutFile << quantity << endl;
OutFile << v_point << endl;
OutFile << item_P_company << endl;
OutFile << item_ypro << endl;

cout << "the value of the seperate print function : \n"
<< item_name << "\n" << item_num << "\n" <<item_ypro
<< item_P_company << endl;
}


[/code]
Topic archived. No new replies allowed.