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

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 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试