So I have written a C++ project which reads a file into a string.
//func to read file into string
std::string readFile( const std::string& fileName )
{
std::ifstream ifs( fileName );
return std::string((std::istreambuf_iterator<char>(ifs)),
(std::istreambuf_iterator<char>()));
}
//func call in main
std::string text = readFile("test.txt");
This is the code I use for this.
I am using CLion to write my code. I changed the standard compiler to clang++. When I run the main.cpp directly in CLion the program can't read the file. There is no error code, but when I am debugging the program it says that the parameter fileName has an incomplete type.
When I compile the main.cpp in the terminal with
clang++ -std=c++14 main.cpp -o histogram
and then run it, it can read the file and the program works as it should do.
Why does it work in the terminal but not in CLion?