小编Sun*_*the的帖子

从类型为 'std::basic_string<char> 的右值对类型为 'std::string& 的非常量引用进行无效初始化

bool hasWord(int y, int x, string &word) {
    if(!inRange(y, x)) return false; 
    if(board[y][x] != word[0])  return false; 
    if(word.size() == 1) return true; 
    for(int direction = 0; direction < 8; direction++) {
        int nextX = x + dx[direction];
        int nextY = y + dy[direction];
        if(hasWord(nextY, nextX, word.substr(1)))  // <--- This
            return true;
    }
return false; }
Run Code Online (Sandbox Code Playgroud)

错误:从类型为 'std::basic_string' 的右值对类型为 'std::string& {aka std::basic_string&}' 的非常量引用进行无效初始化 if(hasWord(nextY, nextX, word.substr(1)) )

为什么我错了?

c++ string c++11

4
推荐指数
1
解决办法
1万
查看次数

fs.FileRead -&gt; TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串、缓冲区或 URL 类型之一。接收类型未定义

function openFileDialog() {
  dialog.showOpenDialog(win, {
    properties: ['openFile']
  } , filepath  => {

    if (filepath) {
      fs.writeFile('path.txt', filepath, function (err, data) {
        if (err) console.log(err);
      });
      scanFile(filepath)
    }
  })
}

function scanFile(filepath) {
  if(!filepath || filepath[0] == 'undefined') return;
  console.log(filepath)
  fs.readFile(filepath,"utf8", (err,data) => { // ----> *ERROR*
    if(err) console.log(err);
    var arr = [];
    if (data.substr(-4) === '.mp3' || data.substr(-4) === '.m4a'
    || data.substr(-5) === '.webm' || data.substr(-4) === '.wav'
    || data.substr(-4) === '.aac' || data.substr(-4) === '.ogg'
    || data.substr(-5) === '.opus') …
Run Code Online (Sandbox Code Playgroud)

javascript fs node.js electron

2
推荐指数
1
解决办法
3万
查看次数

标签 统计

c++ ×1

c++11 ×1

electron ×1

fs ×1

javascript ×1

node.js ×1

string ×1