How to use getVariable in class

I need to output the information I got from the file back to a new file. But I am having understanding how to use the get command. ex. song[i].getLast();

I am getting undefined reference for the 3 get variables I am using.
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include<iostream>
#include<string.h>
#include<fstream>
const int N=5;
using namespace std;

class Quote
{
public:
    Quote();
    string getFirst();
    string getLast();
    string getQ();
    void set(string l,string f,string qu)
    {
        last=l;
        first=f;
        q=qu;
    }
    void operator=(Quote);
    int operator==(Quote);
    int operator>(Quote);
private:
    string last;
    string first;
    string q;
};

Quote::Quote()
{
    first="First";
    last="Last";
    q="Quote";
}
/*void Quote::operator ==(Quote song)
{

}*/

int main()
{
    Quote song[N];
    string l;
    string f;
    string qu;
    ifstream quote("G://CompSci III//QuoteComp.txt");
    if(quote.is_open())
    {
        while(quote.good())
        {
            for(int i=0; i<N; i++)
            {
                getline(quote,l,',');
                getline(quote,f,',');
                getline(quote,qu);
                song[i].set(l,f,qu);
            }
            quote.close();
        }
    }
    else
    {
        cout<<"No input."<<endl;
    }
    ofstream quoteout("G://CompSci III//QuoteCompOutput.txt");
    if(quoteout.is_open())
    {
        for(int i=0; i<N; i++)
        {
            quoteout<<song[i].getLast();
            quoteout<<song[i].getFirst();
            quoteout<<song[i].getQ();
            quoteout<<endl;
        }
        quoteout.close();
    }
    else
    {
        cout<<"No ouput."<<endl;
    }

}
Have you defined the functions? Right now it looks like you only have the declarations.
When I get the line from the file doesn't that declare it?
eman2013 wrote:
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
class Quote
{
public:
    Quote(); //this is a declaration
    string getFirst(); //this is a declaration
    string getLast(); //this is a declaration
    string getQ(); //this is a declaration
    void set(string l,string f,string qu) //this is a definition
    {
        last=l;
        first=f;
        q=qu;
    }
    void operator=(Quote); //this is a declaration
    int operator==(Quote); //this is a declaration
    int operator>(Quote); //this is a declaration
private:
    string last;
    string first;
    string q;
};

Quote::Quote() //this is a definition
{
    first="First";
    last="Last";
    q="Quote";
}
/*void Quote::operator ==(Quote song) //this is a definition
{

}*/
so should I set getFirst=to song[i].f and where would I do this?

The main point of the program is to the first last and quote form a file and put them in order by last and first name
You need to write the code for the actual method, to tell it what to do. The compiler can't magically read your mind to find out what you want it to do and write it for you.

If you want a function called getFirst() that returns the value of first, then write it to do that. If you want it to do something else, then write that instead.
Could you give me an example or website where someone has already written a code for that?
Thank you!
Topic archived. No new replies allowed.