Solved

C++ String Class Help

Posted on 2003-11-18
6
351 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
Comment Utility
Drop the .h from iostream.h:
#include <iostream>
0
 
LVL 1

Author Comment

by:fluked
Comment Utility
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_
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 1

Author Comment

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

Expert Comment

by:_ys_
Comment Utility
I've often seen this:

namespace MyNS
{
#include <map>
}

and it confuses the compiler big time.
0
 
LVL 1

Author Comment

by:fluked
Comment Utility
ahh that can be a big mess
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

771 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

10 Experts available now in Live!

Get 1:1 Help Now