Solved

C++ String Class Help

Posted on 2003-11-18
6
358 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to understand recursion 12 229
Compile GLUT with Visual Studio 2015 1 172
sorting efficency of sorting algorithm 30 121
DCT of  2D array using fftw in c++ 9 63
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

861 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