Solved

C++ String Class Help

Posted on 2003-11-18
6
353 Views
Last Modified: 2010-04-01
error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (
or there is no acceptable conversion)
Error executing cl.exe.


I keep getting that error when I try to cout a array from a structure. This is the piece of code.
----------------------------
#include <iostream.h>
#include <string>
using namespace std;


struct record{
      int key;
      string firstName;
      string lastName;
      int studentid;
      int courseID;
      string coursename;
      double courseMark;
};



string Getfirstname();


int main(void)
{
      
      record Database[100];//reserve memory for 100 records
      int i=0;
      char reply;

      do{
                  
      Database[i].key=i;
      Database[i].firstName=Getfirstname();      
      
      cout<<"\nwould you like to enter another student in the database? (y) or (n) ";
      cin>>reply;
      
      
      }while(reply=='y');
            
      cout<<Database[0].firstName; //THIS LINE ERROR
   

      
return 0;
}


string Getfirstname(void){
char firstName[50]; string final;
cout <<"\nplease enter the number of hours worked ";
cin.getline(firstName,50);
final.assign(firstName);
return firstName;
}

--------------------------------------

Anyone got any suggestions please.
-eli
0
Comment
Question by:fluked
  • 3
  • 3
6 Comments
 
LVL 9

Accepted Solution

by:
_ys_ earned 25 total points
ID: 9772809
Drop the .h from iostream.h:
#include <iostream>
0
 
LVL 1

Author Comment

by:fluked
ID: 9772852
thank you a lot. Do you know why I had to remove the h from the input/output class ?
0
 
LVL 9

Expert Comment

by:_ys_
ID: 9772869
The simple answer is because it's in the standard

It centres around the std namespace. Don't mix and match the old and new headers.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:fluked
ID: 9772882
ok Thank you im a newbie at c++ ;)
0
 
LVL 9

Expert Comment

by:_ys_
ID: 9772894
I've often seen this:

namespace MyNS
{
#include <map>
}

and it confuses the compiler big time.
0
 
LVL 1

Author Comment

by:fluked
ID: 9772901
ahh that can be a big mess
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
getting a fire fox page (view page source ) in c++ 6 42
Arduino EDI - Programming language 3 80
Unable to start eclipse ? 17 134
Path to  STL Map header file 1 44
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now