Compare function for two strings of objects?

I believed that there was a compare function but my compiler does not agree with me...

The following code is throwing errors saying my class has no member named 'compare'. It doesn't but I thought there was a compare function within a library which I've been 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
bool Library::SearchByTitle(Book title){
	Library comp;
	for(size_t count = 0; count < used; count++){
		if((title.compare(books[count].get_title())) == 0){
			books[count].output(cout);
			return true;
		}
	}
	return false;
}



bool Library::SearchByAuthorOut(Book author){
	for(size_t count = 0; count < used; count++){
			if((author.compare(books[count].get_author())) == 0){
				books[count].output(cout);
				return true;
			}
		}
		return false;
	
}


//remove's the book		
void Library::RemoveBook(Book title){
	bool temp = false;
	Book tmp;
	size_t count = 0;
	for(count = 0; count < used; count++){
		if((title.compare(books[count].get_title())) == 0){
			books[count].output(cout);
			temp = true;
			break;
		}
	}

	if(temp){
		tmp = books[used-1];
		books[used-1] = books[count];
		books[count] = tmp;
		used--;
	}
	else{
		cout<<"Your book was not found.\n";
		cout<<"Please make sure you entered the exact title.\n";
	}
}
Well. Yes, std::string does have a compare function - http://www.cplusplus.com/reference/string/string/compare/

author.compare

author is of type "Book", not of type std::string, so Im not sure what you're expecting.
Last edited on
Well that was embarrassing, just forgot the .get_title() and .get_author() after the type book.... Thank you TarikNeaj I don't know how I didn't see that.
haha happens =) goodluck^^
Topic archived. No new replies allowed.