Cannot Convert Const String to Char*
I keep getting this error. What does it mean, and how can I fix it?
The error:
AddressBook.cpp:11: error: cannot convert ‘std::string’ to ‘char*’ for argument ‘1’ to ‘char* strcpy(char*, const char*)’
file snippet: AddressBook.cpp
1 2 3 4 5 6 7 8 9 10 11 12
|
#include "AddressBook.h"
#include <string>
#include <cstring>
using namespace std;
string firstName;
void AddressBook::SetFirstName(const string fName)
{
strcpy(firstName, fName);
}
|
file snippet: AddressBook.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#ifndef ADDRESSBOOK_H_
#define ADDRESSBOOK_H_
#include <string>
#include <cstring>
using namespace std;
class AddressBook {
private:
string firstName;
public:
void SetFirstName(const string fName);
};
#endif /* ADDRESSBOOK_H_ */
|
I tried looking online and in my book, but nothing was much help. Any ideas? I'd really appreciate your help!
You can assign strings like this:
1 2 3 4
|
void AddressBook::SetFirstName(const string fName)
{
firstName= fName;
}
|
Thank you!
Topic archived. No new replies allowed.