C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 3rd, 2015, 09:18 PM
pentay pentay is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2015
Posts: 1 pentay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 38 m 42 sec
Reputation Power: 0
Syntax errors - Vector<string> - string compare

Hello.
I'm have some serious issues here and can use your help.
In this file I have 2 classes and a main. The MediaDescription class holds information on a file. The MediaLibrary class holds MediaDescriptions in a vector.
Where I need help is in the MediaLibrary methods add(), remove(), getTitles(), getMusicTitles(), and getVideoTitles().
I know it seems like a lot, but they basically suffer from the same issue, as can be seen in remove(), the 'if (library[i].getTitle() == stringname)' statement.
When I compile it, I get this error:
Code:
'class basic_string<char>' has no member named 'getTitle'

Everything else complies fine.
My question, besides any coding mistakes, is how do I access the 'title' field of the MediaDescription object located in vector<MediaDescription> library at index 3 and compare it to the string passed to the method?

Code:
#include <string>
#include <vector>
#include <iostream>

using namespace std;

class MediaDescription;
class MediaLibrary;

//***** CLASSES
class MediaLibrary {
	public:
		// constructor
		MediaLibrary();

		// methods
		bool add(MediaDescription);
		bool remove(string);
		MediaDescription get(string);
		vector<string> getTitles();
		vector<string> getMusicTitles();
		vector<string> getVideoTitles();
		
 	private:
 		vector<string> library;
};

class MediaDescription {
	public:
		// constructors
		MediaDescription(string, string, string, string, string, string);

		// method
		string print();

		// getters
		string getTitle();
		string getMediaType();
		string getAuthor();
		string getAlbum();
		string getGenre();
		string getFilename();

		// setters
		void setMediaType(string);
		void setAuthor(string);
		void setAlbum(string);
		void setGenre(string);
		void setFilename(string);

	private:
		string title;
		string mediaType;
		string author;
		string album;
		string genre;
		string filename;

		// constructor
		MediaDescription();
		
		// setter
		void setTitle(string);
};

int main() {
	MediaLibrary library;
	
	vector<string> titles;
	
	library.add(MediaDescription("Music", "Come Monday", "Jimmy Buffett",
	"Greatest Hits", "Island", "ComeMonday.mp3"));
	
	titles = library.getTitles();
	for (int i = 0; i < titles.size(); i++) {
		cout << titles[i] << endl;
	}
}

//***** CONSTRUCTORS
MediaLibrary::MediaLibrary() {
	vector<MediaDescription> library;
}

MediaDescription::MediaDescription(string mt, string t, string au, string al,
string g, string fn) {
	mediaType = mt;
	title = t;
	author = au;
	album = al;
	genre = g;
	filename = fn;
}

MediaDescription::MediaDescription() {
	mediaType = "";
	title = "";
	author = "";
	album = "";
	genre = "";
	filename = "";
}

//***** METHODS
bool MediaLibrary::add(MediaDescription aClip) {
	bool success = true;
// help
	return success;
}

bool MediaLibrary::remove(string aTitle) {
	bool success = false;
//
//	for (int i = 0; i < library.size(); i++) {
//		if (library[i].getTitle() == aTitle) {
//			library.erase(i);
//			success = true;
//		}
//	}
	return success;
}

MediaDescription MediaLibrary::get(string aTitle) {
}

vector<string> MediaLibrary::getTitles() {
	vector<string> result;
//	
//	for (int i = 0; i < library.size(); i++) {
//		result += library[i];
//		
//		if (i <= list.size()-2) {
//			result += ", ";
//		}
//	}
	return result;
}

vector<string> MediaLibrary::getMusicTitles() {
	vector<string> titles;
//	
//	for (int i = 0; i < library.size(); i++) {
//		if (library[i].getMediaType() == "Music") {
//			titles += library[i];
//		}
//	}
	return titles;
}

vector<string> MediaLibrary::getVideoTitles() {
	vector<string> titles;
//
//	for (int i = 0; i < library.size(); i++) {
//		if (library.at(i).getTitle() == "Video") {
//			titles += library[i];
//		}
//	}
	return titles;
}


string MediaDescription::print() {
 	vector<string> list;
 	
 	string result;

	list.push_back(mediaType);
	list.push_back(title);
	list.push_back(author);
	list.push_back(album);
	list.push_back(genre);
	list.push_back(filename);
	
	for (int i = 0; i < list.size(); i++) {
		result += list[i];
		
		if (i <= list.size()-2) {
			result += ", ";
		}
	}
	return result;
}

//***** GETTERS
string MediaDescription::getTitle() {return title;}
string MediaDescription::getMediaType() {return mediaType;}
string MediaDescription::getAuthor() {return author;}
string MediaDescription::getAlbum() {return album;}
string MediaDescription::getGenre() {return genre;}
string MediaDescription::getFilename() {return filename;}

//***** SETTERS
void MediaDescription::setTitle(string value) {title = value;}
void MediaDescription::setMediaType(string value) {mediaType = value;}
void MediaDescription::setAuthor(string value) {author = value;}
void MediaDescription::setAlbum(string value) {album = value;}
void MediaDescription::setGenre(string value) {genre = value;}
void MediaDescription::setFilename(string value) {filename = value;}

Thank you for your assistance!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Syntax errors - Vector<string> - string compare


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap