1 Replies - 554 Views - Last Post: 04 December 2012 - 04:38 PM Rate Topic: -----

#1 andrew73a  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-September 12

Error convert parameter 1 from string to char

Posted 04 December 2012 - 04:29 PM

Hi everyone. I am good on this program except I am getting an error on line 111 that says

error C2664: 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::getline(_Elem *,std::streamsize)' : cannot convert parameter 1 from 'std::string [100]' to 'char *'


I know it's not supposed to be a char because that would only get one letter instead of a whole name. Please help. And THank You in advance.



//This program demostrates a class and a derived class with constructors.

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

class Employee
{
private:
string EmpName;
int EmpNum;
int HireDate;

public:
void setEmpName(string);
void setEmpNum(int);
void setHireDate(int);
string getEmpName() const;
int getEmpNum() const;
int getHireDate() const;
Employee();
};

void Employee::setEmpName(string x)
{
EmpName = x;
}

void Employee::setEmpNum(int y)
{
EmpNum = y;
}

void Employee::setHireDate(int z)
{
HireDate = z;
}

string Employee::getEmpName() const
{
return EmpName;
}

int Employee::getEmpNum() const
{
return EmpNum;
}

int Employee::getHireDate() const
{
return HireDate;
}

Employee::Employee()
{
cout << "I will ask you some questions about an employee.\n\n";
}

class ProductionWorker : public Employee
{
private:
int Shift;
double HourlyPayRate;

public:
void setShift(int);
void setHourlyPayRate(double);
int getShift() const;
double getHourlyPayRate() const;
ProductionWorker();
};

void ProductionWorker::setShift(int a)
{
Shift = a;
}

void ProductionWorker::setHourlyPayRate(double B)/>
{
HourlyPayRate = b;
}

int ProductionWorker::getShift() const
{
return Shift;
}

double ProductionWorker::getHourlyPayRate() const
{
return HourlyPayRate;
}

ProductionWorker::ProductionWorker()
{
cout << "Input the information requested and\n";
cout << "I will display the employee's information.\n";
cout << "******************************************\n\n\n";
}

int main()
{
ProductionWorker info;
string name[100];
int num;
int date;
int shift;
double rate;

cout << "\nWhat is the employee's name? ";
cin.getline(name, 100);

cout << "\nWhat is the employee's number? ";
cin >> num;

cout << "\nWhat is the employee's hire date?\n";
cout << "(Month day  year\n";
cout << "in this format MMDDYYYY\nfor example 01091987. ";
cin >> date;

cout << "\nDoes the employee work shift 1 or shift 2? ";
cin >> shift;

cout << "\nHow much does the employee make per hour? ";
cin >> rate;


info.setEmpName(name[100]);
info.setEmpNum(num);
info.setHireDate(date);
info.setShift(shift);
info.setHourlyPayRate(rate);

cout << "\n\nHere is the employee's data:\n\n";
cout << "Employee's Name:" << info.getEmpName() << endl;
cout << "\nEmployee's Number:    " << info.getEmpNum() << endl;
cout << "\nEmployee's Hire Date: " << info.getHireDate() << endl;
cout << "\nEmployee's Shift:     " << info.getShift() << endl;
cout << setprecision(2) << fixed;
cout << "\nHourly Pay Rate:      $" << info.getHourlyPayRate() << endl << endl;

return 0;
}



Is This A Good Question/Topic? 0
  • +

Replies To: Error convert parameter 1 from string to char

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2153
  • View blog
  • Posts: 3,311
  • Joined: 21-June 11

Re: Error convert parameter 1 from string to char

Posted 04 December 2012 - 04:38 PM

View Postandrew73a, on 05 December 2012 - 12:29 AM, said:

cannot convert parameter 1 from 'std::string [100]' to 'char *'


I know it's not supposed to be a char because that would only get one letter instead of a whole name.


char* is not the same thing as char. And yes, the member function getline takes a char pointer as its first argument. There is also the free function getline which takes a stream as its first argument and a string as its second. However there's no getline function that takes an array of strings as an argument.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1