trouble outputing string object to screen.

This is a discussion on trouble outputing string object to screen. within the C++ Programming forums, part of the General Programming Boards category; Code: void ListFileMem(StudentRecord** Records, int numRecords){ cout<<"LIST RECORDS FROM MEMORY"; string fullname, firstname, lastname; if (numRecords>0) { for (int k=0; ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    18

    trouble outputing string object to screen.

    Code:
     void ListFileMem(StudentRecord** Records, int numRecords){
    	cout<<"LIST RECORDS FROM MEMORY";
    	string fullname, firstname, lastname;
    	if (numRecords>0)
    	{
    		for (int k=0; k<numRecords;k++)
    		{
    			firstname=Records[k]->firstName;
    			firstname+=" ";
    			lastname=Records[k]->lastName;
    			fullname=firstname;
    			fullname+=lastname;
    			cout<< fullname; //compiler does not like this. why? //line 269
    			//cout<<"Record"<<k<<"\n\t"<<"Name: " << fullname;cout<<"\n\t"<<"ID:"<<Records[k]->id
    			//	<<"  "<<"Mark:"<<Records[k]->mark<<endl;;
    		}
          }
    	else
    	
    		cout<<"memory empty, unable to list\n";
    
    
    
    
    }
    Code:
    getting error message from ms 2003 compiler:
    n:\assignment0.cpp(269): error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
    what is wrong?
    Last edited by cmasri; 01-17-2007 at 07:45 PM.

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    n:\assignment0.cpp(269):
    Where is line number 269? Post a short working example that demonstrates your problem.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,318
    >> binary '<<' : no operator found which takes a right-hand operand of type 'std::string'
    You switched to string. Good choice. You have to #include <string> in the files that use it. Doing so will probably get rid of the error.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM
  4. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 10:06 PM
  5. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21