注册 登录
编程论坛 C++教室

求大佬指点什么原因unexpected token '{' following declaration of 'main'

each_others 发布于 2019-12-30 19:17, 4161 次点击
#include<stdio.h>
int maxchar(int a,int b)
{
    if(a>b)
        return a;
    else
        return b;
}
int main
{
    int a,b,c,m;
    cin<<a<<b<<c;
    m=maxchar(maxchar(a,b),c);
    cout<<"3个字符串的最大值为"<<m<<endl
}
error C2239: unexpected token '{' following declaration of 'main'
8 回复
#2
叶纤2019-12-30 21:34
我不是大佬鸥,也是一枚小白鹅,你的代码我是实在看不下去了,
先不说头文件是不是C++的,回归正题…1、int main改为int main(){};
2、cin<<...<<改为cin>>...>>;3、m=maxchar(maxchar(a,b),c);这一句话当你不会函数的时候可以一步步的来,太急自己学不会,别人也看不懂你的意思
#3
叶纤2019-12-30 21:41
cout………………endl后面要加;
#4
叶纤2019-12-30 22:17
//这是我帮你改的
#include<iostream>
using namespace std;

int maxchar(int a,int b)
{
    if(a>b)
        {return a;}
    else
        {return b;}
}
int main()
{
    int a,b,c,m;
    cin >> a>>b>>c;
   
    m=maxchar(maxchar(a,b),c);
    cout<<"3个字符串的最大值为"<<m<<endl;
}
#5
each_others2019-12-30 23:04
回复 4楼 叶纤
输入是空格隔开吗,我试一下,谢谢大兄弟
#6
each_others2019-12-30 23:05
回复 3楼 叶纤
这个是复制的时候漏了,哈哈
#7
雪影辰风2020-01-01 12:53
所有的函数后面不管用不用参数都需要一堆小括号
#8
return_02020-02-27 10:20
其实他
return ;
语句外不加花括号也是对的
程序代码:

int maxchar(int a,int b)
{
    if(a>b)
        return a;
    else
        return b;
}
#9
return_02020-02-27 10:21
只要是函数都要有括号
1