make edit to file

hey everyone,
i facing a problem in editing 5 rows of information in a file
i want to make edit in user's choice and make changes to the file
i try so many times , i don't know why the code isn't working



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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
 #include<iostream>
#include<fstream>
#include<string>
using namespace std;
double cost(int n,int m, double k)
{
	double cost = n+((k-0.5)*m) ;
	return cost;

}
void main()
{

	int A[100],B[100],C[100],D[100],E[100],ides[100],w[100],firstkilo[100],addkilo[100];
	ifstream InF;
	int a,b,c,d,e,f, num1,x,y,n,k,counter;
	double h;
	InF.open("d:\\destination.txt");
	ifstream IF("d:\\shipments.txt");
	ofstream OF("d:\\shipments.txt");
	string name1;
	char ans='y';
	for(int j=0;j<100;j++){
		InF>>num1>>name1>>x>>y;
		ides[j]=num1;
		firstkilo[j]=x;
		addkilo[j]=y;
	}
	for(int i=0;i<100 && !InF.eof();i++){
		IF>>a>>b>>c>>d>>e;
		A[i]=a;
		B[i]=b;
		C[i]=c;
		counter=i;
		cout <<A[i];
	}
	while(tolower(ans)=='y'){
		cout<<"enter the ship ID to edit ";
		cin>>n;
		for(int i=0;i<counter;i++){
			if(n==A[i]){
				cout<<"enter new destination ID "<<endl;
				cin>>k;
				for(int j=0;j<100;j++){
					if(k==ides[j]){
						D[i]=firstkilo[j];
						E[i]=addkilo[j];
						cout<<"enter the weight"<<endl;
						cin>>h;
						w[i]=h;
					}
				}
			}
		}
		cout<<"continue? "<<endl;
	}

	for(int i=0;i<counter;i++){
		OF<<A[i]<<"  "<<B[i]<<"  "<<C[i]<<"  "<<w[i]<<cost( D[i], E[i], w[i]);
	}

}
I think the problem is in lines 19 and 20.
You opened the desitinations.txt file but never opened the shipments.txt file.
Try changing your lines 19 and 20 to:
1
2
3
4
ifstream IF;
IF.open("d:\\shipments.txt");
ofstream OF;
OF.open("d:\\shipments.txt");
Explain better what you mean by
code isn't working
the code is supposed to edit a row of information inside a file , but it is not editing anything
Topic archived. No new replies allowed.