comparing strings goes wrong

I'm comparing the contents of two vectors. The data from the infile is read in correctly, but when i compare the contents of the vectors, it matches 2 strings that are not the same. What's going wrong?

1
2
3
4
5
6
7
    for (int i=0; i<vectorsize(appendix); i++)
        for (int j=0; j<vectorsize(compounds); j++)
            if (appendix[i]==compounds[j])
            {
                outfile << compounds[j] << " " << appendix[j] << " " << appendixint[j] << endl;
            }
    return 0;



context:
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
int main()
{
    int number=0;
    string appen;
    string comp;
    int mass=0;
    int volgende=0;
    ifstream infile;
    ofstream outfile;
    infile.open("appendixout.txt");
    outfile.open("vergeleken.txt");
    while (infile)
    {
        infile >> appen;
        if (appen=="@")
        {
            volgende++;
        }
        if (appen!="@")
        {
            if (volgende==0)
            {
                appendix.push_back(appen);
                infile >> mass;
                appendixint.push_back(mass);
            }
            else
                compounds.push_back(appen);
        }
    }
    for (int i=0; i<vectorsize(appendix); i++)
        for (int j=0; j<vectorsize(compounds); j++)
            if (appendix[i]==compounds[j])
            {
                outfile << compounds[j] << " " << appendix[j] << " " << appendixint[j] << endl;
            }
    return 0;


input file: https://pastebin.com/pgAjjGKB
output file: https://pastebin.com/GEJSZdGB
it matches 2 strings that are not the same

How do you know they're not the same?

I see that even though you match appendix[i] and compounds[j], you don't write appendix[i] to the output.
I feel so stupid now. That fixed it, thanks.
Topic archived. No new replies allowed.