提问人:Ahsan 提问时间:10/25/2019 最后编辑:Ahsan 更新时间:10/25/2019 访问量:216
Intellij 与 Visual Studio。错误:基类“std::__1::ios_base”具有私有复制构造函数
Intellij vs Visual Studio. error: base class 'std::__1::ios_base' has private copy constructor
问:
我的代码在 Clion 中完美运行。但是,当我尝试在Visual Studio中编译时,出现以下错误:错误:基类 'std::__1::ios_base' 具有私有复制构造函数。
主 .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;
}
读取文件:.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);
我到处寻找解决方案,我顺便参考一下。Clion 的 IDE 说一切都很好。我不明白为什么这不起作用。在 ReadFile 中调用 TextToPuzzle 时似乎出现了错误。
看完评论后: 这是错误:
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
^
答: 暂无答案
评论
using
std::string&
TextToPuzzle
vector<stringstream> puzzle_list
我是你的恶棍正在存储副本。看看移动 s 是否有意义。vector
stringstream
puzzle_list.push_back(stringstream(Trim(line_contents)));