강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

배규혁님의 프로필 이미지
배규혁

작성한 질문수

홍정모의 따라하며 배우는 C++

6.6 C언어 스타일의 배열 문자열

[12:34] 질문 있습니다.

작성

·

271

0

strcat_s를 연습하던 도중에 C6386 error 가 발생해서 질문드립니다. 구글링해도 무슨 말인지 이해가 안갑니다...ㅠ strcat_s에서 size를 11로 수정했을 때는 에러가 발생하지 않지만 값이 출력되지 않습니다...

또 Release일 때랑 Debug일 때랑 결과가 다른데 그 이유도 같이 궁금합니다.

<code>

#include <iostream>
#include <cstring>

using namespace std;

int main()
{
	char source[] = "Copy this!";
	char dest[] = "do it again!";
	
	strcat_s(source, 50, dest);

	cout << source << endl;
	cout << dest << endl;

	return 0;
}

이 때 strcat_s line에 밑줄 쳐지면서 C6386 error 라고 뜹니다. 

<Debug일 때 결과>

Copy this!do it again!
do it again!

C:\Users\wawoo\source\repos\Inflearn 강의용 6\Debug\Chapter6_6.exe (process 12792) exited with code -1073740791.
Press any key to close this window . . .

runtime error 뜨면서 값은 제대로 출력이 됩니다.

<Release일 때의 결과>

Copy this!do it again!
 it again!

C:\Users\wawoo\source\repos\Inflearn 강의용 6\Release\Chapter6_6.exe (process 3516) exited with code 0.
Press any key to close this window . . .

앞에 do 가 생략돼서 나옵니다...

감사합니다!

답변 1

0

안녕하세요?
https://en.cppreference.com/w/c/string/byte/strcat
strcat_s의 사용법을 다시 확인해보시고
크기가 11인 배열에 이어서 데이터를 쓰면 무슨 일이 일어날까? 를 고민해보셨으면 좋겠네요.

배규혁님의 프로필 이미지
배규혁

작성한 질문수

질문하기