Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
479 views
in Technique[技术] by (71.8m points)

c++ - gets() function is not available in Visual studio 2015 community

I have faced a compiler error(c3861) in my newly installed Visual studio community 2015 IDE:

I just want to use gets() function from stdio.h library, and i have included stdio.h file in my program, but compiler show me a compiler error like below:

error C3861: 'gets': identifier not found 

What should i do to compile my program correctly withgets() function.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Since C11, gets is replaced by gets_s. The gets() function does not perform bounds checking, therefore this function is extremely vulnerable to buffer-overflows. The recommended replacements are gets_s() or fgets()

gets_s(buf);
fgets(buf, sizeof(buf), stdin);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...