Bing碎冰 2022-01-15 17:36 采纳率: 83.3%
浏览 76
已结题

c++ 编译器没报错但是poj编译错误


#include <iostream>
#include <queue>
using namespace std;
char a[22][22];
int turn[4][2] = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}};
typedef struct m
{
    int x, y;
} ob;
int main()
{
    int w, h;
    while (cin >> w >> h)
    {
        ob st;
        for (int i = 1; i <= h; i++)
        {
            getchar();
            for (int j = 1; j <= w; j++)
            {
                cin >> a[i][j];
                if (a[i][j] == '@')
                {
                    st.x = j, st.y = i;
                }
            }
        }
        int sum = 1;
        queue<ob> line;
        line.push(st);
        a[line.front().y][line.front().x] = 0;
        do 
        {
           

            for (int i = 0; i < 4; i++)
            {
                if (a[line.front().y + turn[i][1]][line.front().x + turn[i][0]] == '.') 
                {                                                                       
                    line.push({line.front().x + turn[i][0], line.front().y + turn[i][1]});
                    a[line.front().y + turn[i][1]][line.front().x + turn[i][0]] = 0;
                    sum++;
                }
            }
            line.pop();
        } while (line.size());
        cout << sum<<endl;
    }
    return 0;
}

附上oj信息:
Compile Error

Main.cpp
F:\temp\23176735.14851\Main.cpp(40) : error C2143: syntax error : missing ')' before '{'
F:\temp\23176735.14851\Main.cpp(40) : error C2660: 'std::queue<_Ty>::push' : function does not take 0 arguments
with
[
_Ty=ob
]
F:\temp\23176735.14851\Main.cpp(40) : error C2143: syntax error : missing ';' before '{'
F:\temp\23176735.14851\Main.cpp(40) : error C2143: syntax error : missing ';' before '}'
F:\temp\23176735.14851\Main.cpp(40) : error C2059: syntax error : ')'

  • 写回答

1条回答 默认 最新

  • _GX_ 2022-01-15 20:09
    关注

    因为在第40行你用C++11语法line.push({ ... })使用初始化列表创建结构体,目前主流C++编译默认支持C++11。似乎你们POJ系统仍然默认C++03,而不是C++11。
    你可以把那行修改为

    ob s = {line.front().x + turn[i][0], line.front().y + turn[i][1]};
    line.push(s);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    问题事件

    • 系统已结题 1月23日
    • 已采纳回答 1月15日
    • 创建了问题 1月15日

    悬赏问题

    • ¥15 用keil调试程序保证结果进行led相关闪烁
    • ¥15 paddle训练自己的数据loss降不下去
    • ¥20 用matlab的pdetool解决以下三个问题
    • ¥15 一道python的homework题,老是非零返回求解
    • ¥15 单个福来轮的平衡与侧向滑动是如何做到的?
    • ¥15 嵌入式Linux固件,能直接告诉我crc32校验的区域在哪不,内核的校验我已经找到了,uboot没有
    • ¥20 h3c静态路要求有详细过程
    • ¥15 调制识别中输入为时频图,星座图,眼图等
    • ¥15 数据结构C++的循环、随机数问题
    • ¥15 用sendmessage函数把第三方软件窗体隐藏 会什么再次运行第三方软件时 无法再隐藏了