Интелли против Visual Studio. ошибка: базовый класс 'std :: __ 1 :: ios_base' имеет частный конструктор копирования - PullRequest
1 голос
/ 24 октября 2019

мой код отлично работает в clion. Однако, когда я пытаюсь скомпилировать в Visual Studio, я получаю следующую ошибку: ошибка: базовый класс 'std :: __ 1 :: ios_base' имеет конструктор частной копии.

main.cpp

#include <iostream>
#include <string>
#include <vector>
#include "ReadFile.h"
#include "SudokuPuzzle.h"

/*
 * Write your sudoku program! Do not put all of your code in main.cpp;
 * make new files as necessary.
 *
 * Make sure that the correct .cpp and .h/.hpp files are available to the
 * sudoku and testing executables as necessary.
 * CLion should prompt you to add the right info to the CMakeLists.txt
 * whenever you create new .cpp files.
 */

int main(int argc, char *argv[]) {

    std::cout << "Enter a path to the file of puzzles" << std::endl;
    std::string path;
    getline(cin, path);

    vector<stringstream> puzzles = TextToPuzzle((string &) path);

    for(stringstream &curPuzzle : puzzles) {

       SudokuPuzzle puzzle;
       curPuzzle >> puzzle;
       puzzle.SetArray();
       std::cout << puzzle;


    }

    return EXIT_SUCCESS;
}

readfile.cpp

//
// Created by Ahsan Gilani on 10/20/19.
//
#include "ReadFile.h"

const char* kSpfVersion = "#spf1.0";
const int kNumTiles = 81;



vector<stringstream> TextToPuzzle(string &file_path) {
    vector<stringstream> puzzle_list;
    ifstream file_stream(Trim((const char*) file_path.c_str()));

    if(!file_stream) {
        std::cout << "Failed to read file, unable to find solutions" << std::endl;
        vector<stringstream> empty;
        return empty;
    }
    else {
        std::cout << "File has been read" << std::endl;


        if (!SeperatePuzzles(file_stream, puzzle_list)) {
            vector<stringstream> empty;
            return empty;
        }
    }


    return puzzle_list;
}

bool SeperatePuzzles(ifstream &file_stream, vector<stringstream> &puzzle_list) {

    string line_contents;
    getline(file_stream, line_contents);

    if(Trim(line_contents).compare(kSpfVersion) != 0) {
        std::cout << "This is not a valid SPF file" << std::endl;
        return false;
    }

    while(getline(file_stream, line_contents)) {
        if(ValidPuzzleInput(line_contents)) {
            puzzle_list.push_back(stringstream(Trim(line_contents)));
        }
        else {
            std::cout << "The contents of this file are not valid." << std::endl;
            std::cout << "This line caused an error: " + line_contents << std::endl;
            return false;
        }
    }

    return true;
}

bool ValidPuzzleInput(const string &file_line) {
    if(Trim(file_line).length() != kNumTiles) {
        return false;
    }

    return Trim(file_line).find_first_not_of("123456789_") == string::npos;
}

//method below dervived from: https://stackoverflow.com/questions/25829143/trim-whitespace-from-a-string/25829178
string Trim(const string &str)
{
    size_t first = str.find_first_not_of(' ');
    size_t last = str.find_last_not_of(' ');

    //if there are no characters other than spaces, prevents going out of bounds
    if (first == string::npos) {
        return "";
    }

    return str.substr(first, (last - first + 1));
}


readfile.h

//
// Created by Ahsan Gilani on 10/20/19.
//

#pragma once

#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <fstream>
#include <regex>

using namespace std;

vector<stringstream> TextToPuzzle(string &file_path);
bool SeperatePuzzles(ifstream &file_stream, vector<stringstream> &puzzle_list);
bool ValidPuzzleInput(const string &file_line);

//helper method to trim whitespaces from string
string Trim(const string &str);

Я просмотрел всерешения, и я передаю по ссылке. и IDE Clion говорит все хорошо. Я не могу понять, почему это не работает. Кажется, что ошибка совершается при вызове TextToPuzzle, который находится в ReadFile.

после просмотра комментариев: это ошибка:

Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/streambuf:493:64: error: 
      base class 'std::__1::ios_base' has private copy constructor
_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<char>)

также ссылка, чтобы увидеть, что происходит в visual studio https://github.com/ahsang2/sudokusolver

                                                           ^
...