gpt4 book ai didi

c++ - 没有重载函数的实例 "strcpy_s"与参数列表匹配

转载 作者:行者123 更新时间:2023-11-28 00:04:04 25 4
gpt4 key购买 nike

出于某种原因,一个字符不能进入 strcopy_s();...

#include <iostream>
#include <cstring>

using namespace std;

struct DATE {
int year;
int month;
int date;
};
struct Book {
char name[50];
char author[50];
int id;
DATE date;
};

int main() {
Book book1;
DATE date1;
char bookName, bookAuthor;
int date, year, month;

cout << "Date Of Publishing? " << endl;
cin >> date;
cout << "Month Of Publishing?" << endl;
cin >> month;
cout << "Year Of Publishing?" << endl;
cin >> year;
date1.year = year;
date1.month = month;
date1.date = date;

cout << "Book Name ? " << endl;
cin >> bookName;
cout << "Book Author" << endl;
cin >> bookAuthor;
strcpy_s(book1.name, bookName);
strcpy_s(book1.author, bookAuthor);
return 0;
}

给我错误:

Severity    Code    Description Project File    Line    Suppression State
Error (active) no instance of overloaded function "strcpy_s" matches the argument list Struct c:\Users\Amanuel\Documents\Visual Studio 2015\Projects\Struct\Struct\Source.cpp 38

Severity Code Description Project File Line Suppression State
Error (active) no instance of overloaded function "strcpy_s" matches the argument list Struct c:\Users\Amanuel\Documents\Visual Studio 2015\Projects\Struct\Struct\Source.cpp 39

Severity Code Description Project File Line Suppression State
Error C2665 'strcpy_s': none of the 2 overloads could convert all the argument types Struct c:\users\amanuel\documents\visual studio 2015\projects\struct\struct\source.cpp 38



Severity Code Description Project File Line Suppression State
Error C2665 'strcpy_s': none of the 2 overloads could convert all the argument types Struct c:\users\amanuel\documents\visual studio 2015\projects\struct\struct\source.cpp 39

最佳答案

正确。 strcpy 及其家族使用 char*,而不是 char。他们在 C 字符串上工作。而且您通常不能将 bookName 放入单个字符中。

也就是说,欢迎来到 21 世纪。我们现在使用 std::string,简单多了。

关于c++ - 没有重载函数的实例 "strcpy_s"与参数列表匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36756336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com