
C++ strcpy_s()
下面这个程序是在VC2005下写编译没有通过有谁能帮忙我改一下并指出原因#include"stdafx.h"#include<iostream>usingnamespac...
下面这个程序是在VC2005下写 编译没有通过 有谁能帮忙我改一下 并指出原因
#include "stdafx.h"
#include<iostream>
using namespace std;
int main()
{
CString str = "beijing";
char a[1024];
strcpy_s(a,1024,str);
cout<<a<<endl;
cin.get();
return 0;
}
编译结果如下
1>strcpy.cpp
1>.\strcpy.cpp(12) : error C2065: “CString”: 未声明的标识符
1>.\strcpy.cpp(12) : error C2146: 语法错误 : 缺少“;”(在标识符“str”的前面)
1>.\strcpy.cpp(12) : error C2065: “str”: 未声明的标识符 展开
#include "stdafx.h"
#include<iostream>
using namespace std;
int main()
{
CString str = "beijing";
char a[1024];
strcpy_s(a,1024,str);
cout<<a<<endl;
cin.get();
return 0;
}
编译结果如下
1>strcpy.cpp
1>.\strcpy.cpp(12) : error C2065: “CString”: 未声明的标识符
1>.\strcpy.cpp(12) : error C2146: 语法错误 : 缺少“;”(在标识符“str”的前面)
1>.\strcpy.cpp(12) : error C2065: “str”: 未声明的标识符 展开
3个回答
展开全部
int main(){
string str="beijing";
char a[20];
memset(a,0,20);
memcpy(a,&str[0],7);
cout<<a<<endl;
cin.get();
return 0;
}
string str="beijing";
char a[20];
memset(a,0,20);
memcpy(a,&str[0],7);
cout<<a<<endl;
cin.get();
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?

2025-08-08 广告
说到edl模块产品的生产厂家,深圳市迈力威环保科技有限公司可以了解一下。深圳市迈力威环保科技有限公司是一家专注于超纯水edl(电除盐)技术研发、制造、服务一体化的企业,成立于2012年,专业从事edl膜块技术研发与生产服务。目前公司共有资深...
点击进入详情页
本回答由经理提供
展开全部
缺少头文件cstring
#include<afx.h>
#include<afx.h>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
参考代码:
#include "stdafx.h"
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afx.h>
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
CString str = "beijing";
char a[1024];
strcpy_s(a,1024,str);
cout<<a<<endl;
cin.get();
return 0;
}
#include "stdafx.h"
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afx.h>
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
CString str = "beijing";
char a[1024];
strcpy_s(a,1024,str);
cout<<a<<endl;
cin.get();
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询