0

I'm going to compile a very simple code on onlinegdb.com

The code is as below.

#include <stdio.h>
#include <string.h>

int main()
{
    char s[10] = {0};
    
    strcpy_s(s, 10, "1234567890");
    
    printf("%s", s);
    
    return 0;
}

I chose option Language as C++, C++14 and C++17, but all those are not compiling strcpy_s.

It says:

main.cpp: In function ‘int main()’:
main.cpp:16:33: error: ‘strcpy_s’ was not declared in this scope
     strcpy_s(s, 10, "1234567890");
                                 ^

I googled minutes, but there was no answer.

Doesn't gdb online support c compiler above c++11 ? Help me please. Thanks.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
coding monster
  • 384
  • 4
  • 18

1 Answers1

1

From https://en.cppreference.com/w/c/string/byte/strcpy:

As with all bounds-checked functions, strcpy_s is only guaranteed to be available if __STDC_LIB_EXT1__ is defined by the implementation and if the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before including string.h.

You haven't checked whether __STDC_LIB_EXT1__ is defined (it's not defined by whatever compiler onlinegdb.com is using), and you haven't indicated that you want strcpy_s at all.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • thx. i've tested and realized that onlinegdb doesn't support it. I'll change online c++ site for next time. – coding monster Jul 31 '21 at 08:45
  • Ahh, I've found that linux compilers such as `gcc` or `g++` don't support `strcpy_s()`. My target is to compile for windows c++, so i have to find online windows compilers. – coding monster Aug 02 '21 at 16:18