頁:
[1]
[已解決]新手詢問有關於strcpy的使用
本帖最後由 peterma 於 2018-3-25 06:45 PM 編輯#include<iostream>
#include<string.h>
using namespace std;
class student{
private:
char name;
public:
student(){
};
student(char*s){
strcpy(name,s);
}
void show_data(){
cout << "姓名:"<< name <<endl;
};
};
void main(){
student s1;
cout<<"------------------"<<endl;
student s2("hello,world");
s2.show_data();
system("pause");
};
---------------
以上是我寫的程式碼,請問大大有人知道我到底哪裡錯了,沒辦法過一直顯示錯誤 1 error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. c:\users\petert\documents\visual studio 2013\projects\consoleapplication2\consoleapplication2\source.cpp 15 1 ConsoleApplication2
...<div class='locked'><em>瀏覽完整內容,請先 <a href='member.php?mod=register'>註冊</a> 或 <a href='javascript:;' onclick="lsSubmit()">登入會員</a></em></div><div></div> 請問兩個變數的大小可能不一樣也會造成這種情形嗎? 看上面s好像沒有固定大小 比較的變數長度要一樣喔,例如:strcpy(a,b),b的長度不能比a大,不然會造成內存地址溢出,然後就出現錯誤訊息{:31:}
頁:
[1]