• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 373
  • Last Modified:

C++ String Class Help

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;

      cout<<"\nwould you like to enter another student in the database? (y) or (n) ";
      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 ";
return firstName;


Anyone got any suggestions please.
  • 3
  • 3
1 Solution
Drop the .h from iostream.h:
#include <iostream>
flukedAuthor Commented:
thank you a lot. Do you know why I had to remove the h from the input/output class ?
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.
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

flukedAuthor Commented:
ok Thank you im a newbie at c++ ;)
I've often seen this:

namespace MyNS
#include <map>

and it confuses the compiler big time.
flukedAuthor Commented:
ahh that can be a big mess
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now