?
Solved

C++ String Class Help

Posted on 2003-11-18
6
Medium Priority
?
371 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 100 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

809 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