0

this is the code:

#include <iostream>
#include <queue>
#include <unordered_set>
using namespace std;
string swap(string s, int i, int j) {
    char temp = s[i];
    s[i] = s[j];
    s[j] = temp;
    return s;
}
int slidingPuzzle(vector<vector<int>>& board) {
    int rows = 2;
    int cols = 3;
    string target = "1234560";
    string start = "";

    for (int i = 0; i < rows; i++) {
        for (int j = 0; i < cols; j++) {
            start = start + to_string(board[i][j]);
        }
    }
    vector<vector<int>> neighbour = {
        {1, 3}, {0, 4, 2}, {1, 5}, {0, 4}, {3, 1, 5}, {4, 2},
    };
    queue<string> q;
    unordered_set<string> visited;
    q.push(start);
    visited.insert(start);
    int step = 0;
    while (!q.empty()) {
        int sz = q.size();
        for (int i = 0; i < sz; i++) {
            string cur = q.front();
            if (target == cur) {
                return step;
            }
            int idx = 0;
            for (; cur[idx] != '0'; idx++)
                ;
            for (int adj : neighbour[idx]) {
                string new_board = swap(cur, adj, idx);

                if (!visited.count(new_board)) {
                    q.push(new_board);
                    visited.insert(new_board);
                }
            }
        }
        step++;
    }

    return -1;
}

int main() {
    vector<vector<int>> board = {
        {1, 2, 3},
        {4, 0, 5},
    };
    int a = slidingPuzzle(board);
    cout << a << endl;
}

When I start compiling this code I get the following problem:

main.cpp:11:36: error: a space is required between consecutive right angle brackets (use '> >')
int slidingPuzzle(vector<vector<int>>& board) {
                                   ^~
                                   > >
...

I checked the relevant information and found out that it is because In C++03 and its previous versions, consecutive closing angle brackets (>>) are not supported.

When I check the default c++ version compiled by clang++ program
clang++ -E -x c++ - -dM < /dev/null | grep __cplusplus
with output:
#define __cplusplus 199711L

My question is: How to modify the default c++ version when clang++ compiles?

  • 3
    `-std=c++11` ? I think Apple's (?) clang has an old default. – alfC May 25 '23 at 02:21
  • yep, This solution can be solved.What I want to do is modify the default version instead of entering this parameter every time. – Daesar Lau May 25 '23 at 02:45
  • 2
    I'm somewhat impressed that you knew about all of those other flags, but not `-std`. I also feel like a search should have surfaced this information a lot faster than a question on SO. – sweenish May 25 '23 at 02:46
  • As for that comment, see the dupe. – sweenish May 25 '23 at 02:46
  • No idea how to change the default globally (seems counterproductive also), my recommendations it to learn CMake early rather than later. – alfC May 26 '23 at 04:35

0 Answers0