I want to read the contents of a text file and print them.
What am I doing wrong?
Ifstream not reading file in bin/data/
hey @cesardevelops
you can try to change:
"textfile.txt"
to
ofToDataPath("textfile.txt", true)
OF has some classes to handle the file system, multiplatform etc… like:
https://openframeworks.cc/documentation/utils/ofFile/
https://openframeworks.cc/documentation/utils/ofDirectory/
https://openframeworks.cc///documentation/utils/ofFilePath/
Aslo you can check the bundled examples here:
openFrameworks\examples\input_output
Hey, Thanks for the reply!
I made it work just like this
void ofApp::setup()
{
ofFile file;
file.open(ofToDataPath("textfile.txt"), ofFile::ReadWrite, false);
ofBuffer buff = file.readToBuffer();
cout << buff;
}
What is the “false” value for in file.open()?
https://openframeworks.cc/documentation/utils/ofFile/#show_open
binary set to false if you are reading a text file & want lines split at endline characters automatically