C++ reading, writing errors

Hi everyone, I am struggling with a program. It shows my file reading and writing (ifstream and ofstream) as errors and I can't understand why. Any ideas? (I learn programming in other language, so I hope you'll understand what I am trying to say.)
Last edited on
1. Please post some code. Most of us here have poor mind-reading capabilities.

2. Actually, there is no #2. I've got a wild guess what the problem might be, but I really don't want to tell you what it is because I don't want to confuse you if that's not the problem.
Hello Ilfau. When the compiler sends out errors to you, they can be hard to understand, but if possible you should still post the error here, otherwise, we can't help much.

You should show us both the program source code that is failing, and the compiler error message verbatim.
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
63
64
65
66
67
#include <iostream>
#include <fstream>
#include <iomanip>
void nuskaitymas(int n, int M[], int D[], double W[], double B[], double R[]);
void skaiciavimas(int & d,int & bd, int & rd, double W[], double R[], double B[],int n);
const int Cmax=100;
int main()
{
    int n, M[Cmax], D[Cmax],d,bd,rd;
    double W[Cmax], B[Cmax], R[Cmax];
    ofstream fr("Duomenys.txt");
    nuskaitymas(n, M, D, W, B, R);
    skaiciavimas(d,bd,rd,W,R,B,n);
    fr<<"Derlingiausia diena "<<M[d]<<" "<<D[d]<<endl;
    fr<<"Derlingiausia baravyku diena "<<M[bd]<<" "<<D[bd]<<endl;
    fr<<"Derlingiausia diena "<<M[d]<<" "<<D[d]<<endl;
    fr.close();
    return 0;
}

void nuskaitymas(int n, int M[], int D[], double W[], double B[], double R[])
{

    ifstream fd("Rezultatai.txt");
    fd>>n;
    for(int  i=0;i<n;i++)
    {
        fd>>M[i]<<D[i]<<W[i]<<B[i]<<R[i];
    }
    fd.close();
}

void skaiciavimas(int & d, int & bd, int & rd, double W[], double R[], double B[], int n )
{
    int mas;
    mas=0;
    for(int i=0;i<n;i++)
    {
        if(W[i]>mas)
        {
           mas=W[i];
           d=i;
        }
    }

    int bar=0;
    for(int g=0;g<n;g++)
    {
        if(B[g]>bar)
        {
            bar=B[g];
            bd=g;
        }
    }

    int raud=0;
    for(int j=0;j<n;j++)
    {
        if(R[j]>raud)
        {
            raud=R[j];
            rd=j;
        }

    }

}

That's how a code looks like.
std::
Many times. (Or once if you employ "using namespace std;")

You also have some << where it should be >> on line 28.

Even allowing for the fact that I can't read your language, I can see that you might choose more meaningful names for variables.
Last edited on
Yeaah, thank you so much
Topic archived. No new replies allowed.