The following error occurred when compiling a code named Myfirst.cpp with a g++ in Linux today
myfirst.cpp:In function ' int main () ':
Myfirst.cpp:11:2: Warning: ' char* gets (char*) ' is deprecated (declared at/usr/include/stdio.h:638) [- Wdeprecated-declarations]
Gets (CC);
^
Myfirst.cpp:11:9: Warning: ' char* gets (char*) ' is deprecated (declared at/usr/include/stdio.h:638) [- Wdeprecated-declarations]
Gets (CC);
^
/tmp/ccohyvhf.o:in function ' main ':
Myfirst.cpp: (. text+0xad): warning:the ' gets ' function is dangerous and should not being used.
/tmp/ccohyvhf.o:in function ' __static_initialization_and_destruction_0 (int, int) ':
Myfirst.cpp: (. text+0x103): Undefined reference to ' std::ios_base::init::init () '
Myfirst.cpp: (. text+0x112): Undefined reference to ' std::ios_base::init::~init () '
Collect2:error:ld returned 1 exit status
Careful look at the error message that the Get function is dangerous, specific information please Baidu or Google, but I use Get function only to enter a string of characters, the system can not use, I wrote a
PS: The following operations are done in Linux terminal, the system version is Ubuntu 14.04 LTS
Open Terminal (ctrl+alt+t)
Touch cstdio//Create a file Cstdio, I'm using C + +
Vim cstdio//Edit Cstdio, and add the following content
#include <cstdio>
void Mygets (char *str)
{
int i=0;
scanf ("%c", &str[i]);
while (str[i++]!= ' \ n ')
{
scanf ("%c", &str[i]);
}
str[i-1]=0;//is the default string end in the character array, and the ASCII code for the 0
}
So your own library function is written, I do not know the standard library functions exactly what, but certainly not me, hey
When used, the header file location is added
#include "Cstdio"//is double quotation marks instead of angle brackets
Mygets (str); STR book character array name
You can use the Get function indirectly under Linux.
If you use the C-language notation,
filename of the Cstdio file
Switch
Stdio.h, put the file inside of the
#include <cstdio>
Switch
#include <stdio.h>
Starting address of this article
https://www.textarea.com/suppermary/linux-xia-shiyong-gcc-g-bianyi-daima-shi-gets-hanshu-you-cuowu-564/
The Get function has errors when compiling code using gcc/g++ under Linux