I'm trying to write a c++ program that reads some .txt file, and I've tried several ways of opening the file and verifying it exists but neither compiles. The following are extracts from my code:
#include <fstream>
#include <string>
#include <filesystem>
#include "read_graph.hpp"
ReadGraph::ReadGraph(const std::string filename) : _filename(filename) {}
bool ReadGraph::exists() {
std::ifstream = gfile; // case (1)
std::filesystem::path p(_filename); // case (2)
}
bool ReadGraph::readable() { return false; }
int main() { return 0; }
The following is my CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(graph_generator VERSION 0.1 LANGUAGES CXX)
add_library(read_graph
read_graph.cpp
)
target_compile_features(read_graph PUBLIC cxx_std_20)
add_executable(exec
read_graph.cpp
)
When I try to compile case (1) (i.e case (2) is commented), I get the following error: error: expected unqualified-id std::ifstream = gfile;
.
When I try to compile case (2), I get error: no member named 'filesystem' in namespace 'std' std::filesystem::path p(_filename);
I don't understand what's going on here, as I included all the correct headers, and these are standard libraries in C++ 17 and 20, so from what I understand I don't need to pass additional flags into my CMakeLists.
Thanks in advance