I'm new to C++ and currently using Visual Studio for coding. My strcpy_s() does not work for some reason
#include<iostream>
#include<cstring>
int main(){
char a[]="Hello World!";
strcpy_s(a+6,"C++");
std::cout<<a;
}
This programme should print "Hello C++", however it does not.
I tried other editors (including online C++ IDE) and this issue is fixed. Is there a way to fix this problem in Visual Studio?
Thank you!
strcpy_s requires dest_size. The behavior of strcpy_s is undefined if the source and destination strings overlap.
Possible output: Hello C++
Another solution: