错误:无法将参数1从std :: string转换为char *。困惑为什么它给我这个错误。 [英] Error: Cannot convert parameter 1 from std::string to char*. Confused on why it is giving me this error.
本文介绍了错误:无法将参数1从std :: string转换为char *。困惑为什么它给我这个错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我再次需要一些帮助这个程序的类。也许它,我累了,但我似乎找不到逻辑错误,我相信我在这里。这是我的代码:
So once again I need some help with this program for class. Maybe its that I'm tired but I can't seem to find the logic error I'm sure I've made here. Here is my code:
#include "Book.h"
using namespace std;
void add (char*, char*, int);
void remove (int&);
void list ();
int Count;
Book Bookshelf [4];
int main ()
{
string In;
string N;
string A;
int Y;
int Num;
do
{
cout << "Bookshelf> ";
getline(cin, In);
if (In.compare("add") == 0)
{
cout << "Bookshelf> Enter book: ";
cin >> N >> A >> Y;
add (N,A,Y);
}
else if (In.compare ("remove") == 0)
{
cout << "Bookshelf> Select number: ";
cin >> Num;
remove (Num);
}
else if (In.compare("list") == 0)
{
list ();
}
} while (cin != "quit");
return 0;
}
void add (string N, string A, int Y)
{
if (Bookshelf[4].IsEmpty() == false)
cout << "Error!" << endl;
else
{
Bookshelf[Count] = Book (N,A,Y);
Count++;
}
cout << "Bookshelf> ";
}
错误发生在 add A,Y);
但对于我的生活我不知道为什么这么说。他们看起来像std ::字符串给我。
The error occurs at the line add(N,A,Y);
but for the life of me I can't tell why it is saying that. They both look like std::strings to me. Can anyone explain this to me?
推荐答案
您忘了在文件顶部修改原型。
You have forgotten to modify your prototype at the top of your file.
它仍然说
void add (char*, char*, int);
应为
void add (string, string, int);
这篇关于错误:无法将参数1从std :: string转换为char *。困惑为什么它给我这个错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文