You say you're not using windows, and yet you create paths like this:
std::string file = "Cell\\Cell.txt";
This isn't a file called Cell.txt
in a directory called Cell
, but a file called Cell\Cell.txt
because backslash path separators are a windows-ism, and under other operating systems they're part of the directory or file name. Use a forward slash instead: Cell/Cell.txt
.
Better yet, use the new C++ filesystem libraries to build your paths in a platform-independent sort of manner, and avoid this issue entirely.
#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
int main()
{
auto path = fs::path("Cell") / fs::path("Cell.txt");
std::cout << path.string() << std::endl;
}
This will output
Cell\Cell.txt
under windows and
Cell/Cell.txt
under linux, for example. You can also create directories using create_directory.
(note: this works out of the box on windows under vs2017 and probably 2015, but under g++ you'll need to include an extra library at compile time, like this: g++ -std=c++14 -O2 -Wall -pedantic main.cpp -lstdc++fs
)