Thread: class string error

  1. #1
    Registered User
    Join Date
    Mar 2019
    Posts
    50

    class string error

    Code:
    
    #include<iostream>
    #include<cstdlib>
    #include<string>
    
    
    class GradeBook{
    	private:
    		string name;
    		
    	public:
    		void setName(string nameofCourse){
    			nameofCourse = name;
    		}
    		
    		string getName(){
    			return name
    		}
    };
    
    
    int main(){
    	 GradeBook b1;
    	 
    	 string cname;
    	 
    	 getline(cin , cname);
    	 
    	 b1.setName(cname);
    	 cout << "Welcome to GradeBook for " << b1.getName() << endl;
    	 
    	 system("pause");
    	 return 0;
    	 
    }
    class string error-string-error-png
    I am trying this code and error message.

    Can you please check the issue?

  2. #2
    Registered User
    Join Date
    Mar 2019
    Posts
    50
    Well I've identified error. Thanks for all

  3. #3
    Registered User antred's Avatar
    Join Date
    Apr 2012
    Location
    Germany
    Posts
    257
    Code:
    void setName(string nameofCourse){
        nameofCourse = name
    }
    
    Shouldn't this be:

    Code:
    void setName(string nameofCourse){
        name = nameofCourse;
    }
    
    ?

  4. #4
    Registered User
    Join Date
    Mar 2019
    Posts
    50
    Yeah! there were two errors. One as you are indicating to and the other I haven't used using namespace std;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error using string class type
    By matth in forum C++ Programming
    Replies: 4
    Last Post: 01-11-2006, 05:52 PM
  2. Wierd string/class error
    By Sfpiano in forum C++ Programming
    Replies: 4
    Last Post: 07-13-2005, 06:43 PM
  3. Template <class T1, class T2, class T3> error LNK2019
    By JonAntoine in forum C++ Programming
    Replies: 9
    Last Post: 10-11-2004, 12:25 PM
  4. Assertion Error on string class assignment
    By BigDaddyDrew in forum C++ Programming
    Replies: 2
    Last Post: 03-24-2003, 04:31 PM
  5. Runtime error in Class, string based program.... plz help
    By PotitKing in forum C++ Programming
    Replies: 2
    Last Post: 12-24-2001, 08:15 AM

Tags for this Thread