strcpy_s from an old C/C++ library in C++ program

Hello all,

I am trying to write a program that uses a library, which is rather old and was originally made for use with C, but is supposed to work well with C++.

Library uses function strcpy_s() like this.
 
strcpy_s(name,"tk");

But I get the error: strcpy_s was not declared in this scope

I add #include <string> in the main.cpp. and I am rather sure this is the problem, but I don't know how to solve it.

Any help will be appreciated, thank you.
Kind regards, T
Last edited on
Well the first thing would be that the include file would be <cstring> not <string> the second is I'm not sure if C++ supports the strcpy_s() function. The strcpy_s() was a Microsoft specific function until C11 where these functions became optional. You may need to just stick with the standard C function strcpy().


strcpy_s takes 3 parameters anyway (not just 2 like strcpy).
You are right, changing function from strcpy_s() to strcpy() does clear all the errors.

But are they equivalent in functionality, will I not make changes to how the program works if I replace one with another ?
Since the strcpy_s() function was used incorrectly in the first place, it'll probably work better.

However you may want to think about re-factoring the code to be C++ code using C++ strings instead of C-strings.


Topic archived. No new replies allowed.