【发布时间】:2018-03-13 05:45:19
【问题描述】:
我尝试了很多东西,但没有结果。我用过<cstdio> 但没有帮助。
我再次尝试使用 fget 但没有得到任何好的结果。我使用在线编译器http://rextester.com/l/cpp_online_compiler_gcc
#include <iostream>
#include <string.h>
#include<stdio.h>
#include<cstdio>
using namespace std;
int main() {
bool check;
char sntn[100],word[100],test[20];
gets (word);
gets (sntn);
int j=0,count=0,val,k;
check=true;
while(check) {
for(; sntn[j]==32; j++) {
test[k]=sntn[j];
k++;
}
}
k=0;
j+=1;
val=strcmp(test,word);
if(val==0)
count++;
if(sntn[j]==32) {
j+=1;
check=true;
}
if(sntn[j]=='\0')
check=false;
cout<<endl<<count;
return 0;
}
错误:
source_file.cpp: In function ‘int main()’:
source_file.cpp:9:11: error: ‘gets’ was not declared in this scope
gets (word);
^
【问题讨论】:
-
我省略了
stdio.h并使用了一个cstdio,但仍然出现同样的错误。 -
提示:您可以使用 AStyle 等免费程序在发布代码之前对其进行格式化。
-
只需在命名空间
std和<string>标头中使用string和getline。 -
@Cheersandhth.-Alf,对不起,我是 Stackoverflow 的新手,所以不知道 Astyle。
-
@Cheersandhth.-Alf 请详细说明