2013-01-07 1 views
0

Visual C++ 6.0에서 일부 이전 코드를 컴파일하려고합니다. DSW 파일이 누락되었으므로 모든 코드를 새 작업 공간에 추가하고 있습니다. 뿐만 아니라 a.cpp에서 같은 fopen_s, strncpy_s, strncat_s를 사용하는 다른 기능이 있습니다Visual C++ 6.0에서 * _s를 사용하여 코드 컴파일

#include "vld.h" 
#include "afx.h" 
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <iostream> 
#include "b.h" 

... 

void function_1(char* string1) 
{ 
    char buf[2000]; 
    strcpy_s(&buf[0], 2000, string1); 
    strcat_s(&buf[0], 2000, "_append"); 
    ... 
} 

을 다음과 같이

나는 a.cpp 있습니다.

그리고 b.h 이미 stdio.hstring.h가 있더라도

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

char function_2(unsigned char * string2, int abc, int def) 
{ 
    char buf2[200]; 
    sprintf_s(buf2, 200, "abcdef"); 
    strcat_s(buf2, 200, "ghijkl"); 
} 

, 난 여전히 오류 a.cppb.h 모두

'sprintf_s': undeclared identifier 
'strcat_s': undeclared identifier 
'strcpy_s': undeclared identifier 
'fopen_s': undeclared identifier 
'strncpy_s': undeclared identifier 
'strncat_s': undeclared identifier 

를 얻을.

누락 된 설정이 있습니까? 이러한 오류가 발생하는 이유는 무엇입니까?

+0

직접'200' 또는'2000'을 전달하는 대신'sizeof buf'와'sizeof buf2'를 전달해야합니다. 즉, 배열의 크기를 변경하면 모든 문자열 함수가 자동으로 새 크기로 작동합니다. 이것은'buf'와'buf2'가 배열 타입이라면 작동합니다. 예를 들어,'char *'로 선언되어있는 경우, 이것은 동작하지 않습니다. – dreamlax

답변

2

_s 버전 기능이 Visual Studio 2005에 추가되었습니다. 따라서 최신 Visual Studio 버전을 사용해야합니다.