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

No instance of overloaded function "strcpy_s" matches the argument list

本文关键字:函数 strcpy 实例 重载 参数 列表      更新时间:2023-10-16

由于某种原因,字符不能进入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:UsersAmanuelDocumentsVisual Studio 2015ProjectsStructStructSource.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:UsersAmanuelDocumentsVisual Studio 2015ProjectsStructStructSource.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:usersamanueldocumentsvisual studio 2015projectsstructstructsource.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:usersamanueldocumentsvisual studio 2015projectsstructstructsource.cpp 39  

正确。 strcpy及其家人接受char*,而不是char。它们在 C 字符串上工作。而且你通常不能把一个bookName放到一个角色中。

也就是说,欢迎来到21世纪。我们现在使用std::string,要容易得多。