加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 在以下代码中找不到错误: – 在try()之前预期的unqualifie

发布时间:2020-12-16 09:49:42 所属栏目:百科 来源:网络整理
导读:#includestdio.h#includestring.hvoid try(char s[]){ if(strlen(s)5) { puts("Errorn"); }}int main(){ char string[10]; int T; scanf("%d",T); while(T--) { scanf("%s",string); try(string); } return 0;} 仍然找不到错误…尝试是一个简单的功能,并一
#include<stdio.h>
#include<string.h>
void try(char s[])
{
    if(strlen(s)>5)
    {
        puts("Errorn");
    }
}
int main()
{
    char string[10];
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%s",&string);
        try(string);
    }

    return 0;
}

仍然找不到错误…尝试是一个简单的功能,并一如既往我创建一个函数并调用它.编译器给出错误 – (在’try’之前预期的unqualified-id)

解决方法

我怀疑你是在尝试将代码编译为C而不是C.在C中,try是 reserved word(它用于异常处理).

$gcc test.c
$g++ test.c
test.c:3:6: error: expected unqualified-id before 'try'

您可以使用-x显式设置语言(使用gcc或g):

$gcc -x c test.c
$gcc -x c++ test.c
test.c:3:6: error: expected unqualified-id before 'try'

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读