没有与参数列表匹配的重载函数"strcpy_s"实例
No instance of overloaded function "strcpy_s" matches the argument list
由于某种原因,字符不能进入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
,要容易得多。
相关文章:
- "error: no matching function for call to"构造函数错误
- 什么时候调用组成单元对象的析构函数
- 继承函数的重载解析
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- C++模板来检查友元函数的存在
- 递归函数计算序列中的平方和(并输出过程)
- 对RValue对象调用的LValue ref限定成员函数
- C++ strcpy 函数在少数主要情况下失败
- 在函数 strcpy() 中访问字符数组时出现分段错误
- 如何修复编译错误"此函数或变量可能不安全"(strcpy)
- 如何在C++中实现 strcpy 函数
- 这段代码的输出是什么,它在构造函数中使用 strcpy?
- strcpy 对指针函数的引用
- 使用 strcpy 时构造函数中的分段错误
- C++:strcpy 函数复制空值
- C++传递给函数的 strcpy 指针
- c++控制台程序中strcpy函数的异常.strcpy()中的
- 函数 strcpy 不起作用
- 不了解示例中的行为 - strcpy() 和返回本地数组地址的函数
- 这个带有指针函数的 strcpy 有什么问题?