Dinos_12345 Δημοσ. 15 Μαρτίου 2016 Δημοσ. 15 Μαρτίου 2016 Γεια χαρά στην παρέα! Ξεκίνησα C++ αυτό το εξάμηνο στη σχολή και είμαι λίγο noob ακόμα αλλά, τι error είναι αυτό; Ο γούγλης δεν έδωσε λύση. #include <iostream> #include <string.h> using namespace std; class Movie { private: string m_title; int year_of_making; string production_corp; string director; public: void setTitle(string title); void setYOM(int year); void setDirector(string directors_name); void setProdCorp(string corporation); void printingMethod(); }; Movie::setTitle(string title) { m_title = title; } Movie::setYOM(int year) { year_of_making = year; } Movie::setDirector(string directors_name) { director = directors_name; } Movie::setProdCorp(string corporation) { production_corp = corporation; } Movie::printingMethod() { cout >> "Title: " >> m_title >> endl; cout >> "Year of making: " >> year_of_making >> endl; cout >> "Brought to you by: " >> production_corp >> " Studios" >> endl; cout >> "Directed by: " >> director >> endl; } int main() { Movie title; string mov_tit; int year; string corp; string mov_director; cout << "Give Movie name "; cin >> mov_tit; cout << "Give Year of Making "; cin >> year; cout << "Give Production Corporation "; cin >> corp; cout << "Give Director's name "; cin >> mov_director; title.setTitle(mov_tit); title.setYOM(year); title.setProdCorp(corp); title.setDirector(mov_director); title.printingMethod; return 0; } Any thoughts;
Moderators Kercyn Δημοσ. 15 Μαρτίου 2016 Moderators Δημοσ. 15 Μαρτίου 2016 Ξέχασες τα return types στα function definitions σου. 2
Dinos_12345 Δημοσ. 15 Μαρτίου 2016 Μέλος Δημοσ. 15 Μαρτίου 2016 Τι noob Τώρα γκρινιάζει επειδή "string does not name a type"
Moderators Kercyn Δημοσ. 15 Μαρτίου 2016 Moderators Δημοσ. 15 Μαρτίου 2016 Οι βιβλιοθήκες της C++ δεν έχουν .h στο τέλος. #include <string>
Dinos_12345 Δημοσ. 15 Μαρτίου 2016 Μέλος Δημοσ. 15 Μαρτίου 2016 Οι βιβλιοθήκες της C++ δεν έχουν .h στο τέλος. #include <string> Συννεχίζει να λέει το ίδιο...
Moderators Kercyn Δημοσ. 15 Μαρτίου 2016 Moderators Δημοσ. 15 Μαρτίου 2016 Α έχεις και ανάποδα τα βελάκια στο cout. Πρέπει να είναι <<, όχι >>.
Dinos_12345 Δημοσ. 15 Μαρτίου 2016 Μέλος Δημοσ. 15 Μαρτίου 2016 Δύο θέματα 1)Μετά τις διορθώσεις στα λάθη απροσεξίας που έκανα ακόμα λέει τα ίδια. 2)Γιατί το using namespace std; αν δεν μπει βγάζει 2 τόνους σφάλματα;
gon1332 Δημοσ. 15 Μαρτίου 2016 Δημοσ. 15 Μαρτίου 2016 2) Γιατί τα cout, cin και string ανήκουν στο std namespace. Για να το διορθώσεις βάλε από μπροστά τους std:: . Είναι καλή πρακτική να είσαι explicit με αυτό το θέμα, αλλιώς αργότερα μπορεί να προκύψουν σοβαρά προβλήματα. 1
Dinos_12345 Δημοσ. 15 Μαρτίου 2016 Μέλος Δημοσ. 15 Μαρτίου 2016 Έβαλα std::string αντί για string σε κάθε declaration, λειτουργεί κομπλέ τώρα... 2) Γιατί τα cout, cin και string ανήκουν στο std namespace. Για να το διορθώσεις βάλε από μπροστά τους std:: . Είναι καλή πρακτική να είσαι explicit με αυτό το θέμα, αλλιώς αργότερα μπορεί να προκύψουν σοβαρά προβλήματα. Αν όμως δεν χρησιμοποιώ αυτό τότε δεν δουλεύει ούτε το endl και φαντάζομαι και πολλά άλλα. Επίσης το std:: μπροστά από κάθε cin, cout κλπ είναι άχρηστα keystrokes, δεν υπάρχει πιο σύντομος τρόπος;
defacer Δημοσ. 15 Μαρτίου 2016 Δημοσ. 15 Μαρτίου 2016 Δεν τη μελέτησες προσεκτικά τη σελίδα του link. using std::string; using std::cin; using std::cout; και όσα ακόμα βολεύει. 1
Dinos_12345 Δημοσ. 15 Μαρτίου 2016 Μέλος Δημοσ. 15 Μαρτίου 2016 Ευχαριστώ όλους για τις απαντήσεις/υποδείξεις/πληροφορίες Τελικός κώδικας που τρέχει κομπλέ #include <iostream> #include <string> using namespace std; class Movie { private: string m_title; int year_of_making; string production_corp; string director; public: void setTitle(string title); void setYOM(int year); void setDirector(string directors_name); void setProdCorp(string corporation); void printingMethod(); }; void Movie::setTitle(string title) { m_title = title; } void Movie::setYOM(int year) { year_of_making = year; } void Movie::setDirector(string directors_name) { director = directors_name; } void Movie::setProdCorp(string corporation) { production_corp = corporation; } void Movie::printingMethod() { cout << "Title: " << m_title << endl; cout << "Year of making: " << year_of_making << endl; cout << "Brought to you by: " << production_corp << " Studios" << endl; cout << "Directed by: " << director << endl; } using namespace std; int main() { Movie title; string mov_tit; int year; string corp; string mov_director; cout << "Give Movie name "; cin >> mov_tit; cout << "Give Year of Making "; cin >> year; cout << "Give Production Corporation "; cin >> corp; cout << "Give Director's name "; cin >> mov_director; title.setTitle(mov_tit); title.setYOM(year); title.setProdCorp(corp); title.setDirector(mov_director); title.printingMethod(); return 0; } Φαίνεται καλοέμαθα με την Ruby και τις Internet-ικές γλώσσες και έχω σκουριάσει στα υπόλοιπα...
Προτεινόμενες αναρτήσεις
Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε
Πρέπει να είστε μέλος για να αφήσετε σχόλιο
Δημιουργία λογαριασμού
Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!
Δημιουργία νέου λογαριασμούΣύνδεση
Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.
Συνδεθείτε τώρα