我是C++新手,目前使用Visual Studio进行编码。我的strcpy_s()
由于某种原因无法工作
#include<iostream>
#include<cstring>
int main(){
char a[]="Hello World!";
strcpy_s(a+6,"C++");
std::cout<<a;
}
字符串
这个程序应该打印“Hello C++",但它没有。
我尝试了其他编辑器(包括在线C++ IDE),这个问题得到了解决。有没有办法在Visual Studio中解决这个问题?
谢谢你,谢谢
1条答案
按热度按时间6tr1vspr1#
strcpy_s需要dest_size。如果源字符串和目标字符串重叠,则strcpy_s的行为未定义。
字符串
可能的输出:Hello C++
另一个解决方案是:
型