[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

C++ String Class Help

Posted on 2003-11-18
6
Medium Priority
?
369 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 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.
Suggested Courses

656 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