在以下代码中找不到错误:- 在 try() 之前预期未限定 id
Can't find the error in following code :- expected unqualified-id before try()
#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 是一个简单的函数,我一如既往地创建一个 func 并调用它。编译器给出错误 -(在"try"之前应为非限定 ID)
我怀疑您正在尝试将代码编译为C++而不是C。在C++中,try
是一个保留字(用于异常处理)。
$ 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'
尝试将-x c
添加到调用或将文件重命名为 main.c
。可能是gcc
出于某种原因选择将您的 C 文件编译为 C++。
相关文章:
- 从函数角度看ID到文件路径的内部与外部映射
- 通过组合不同的类型来创建唯一的id
- 我不断收到 [错误] ID 返回 1 退出状态错误,但看不到问题所在
- FFMPEG配置文件级别id大小无效
- 方法内部但循环仍得到预期的不合格id错误C++
- 如何获取 GLFW 窗口 ID?
- 当简单捕获中的标识符显示为参数的声明符 ID 时,没有编译器诊断
- 显示数组中的学生 ID 和最高分
- C++:"("令牌"之前有预期的非限定 id 指向类中成员函数的指针
- 在PostgreSQL中根据它们的ID选择大量行的最快方法是什么?
- Xcode 9.4.1 中的 Apple Mach-O 链接器 (id) 错误
- 错误:令牌 { '{' 之前应存在非限定 ID
- 断言"id < 0"在Qt ActiveX中失败
- C++ Python "try: except:"版本
- C++部分概念 id:显式模板规范顺序/第一个参数的特殊状态的原因是什么?
- 如何根据两个因素组织向量:id 和数量?(C++)
- 在返回 0 之前应为非限定 ID
- 编译器是否必须始终删除 try-catch 块(如果它被证明是非抛出的)
- Direct3D 11 - HLSL - 获取顶点索引 ID
- 在以下代码中找不到错误:- 在 try() 之前预期未限定 id