Thread: Basic file io
View Single Post
Old 05-06-2014, 11:52 AM   #4
Human being with feelings
Xenakios's Avatar
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,059

Looks like the WDL file classes are not designed to help dealing with text data...Writing is fairly trivial, but reading requires more careful handling...

Writing is like :

        WDL_FileWrite outfile("C:\\ssd_tests\\wdl_test_file.txt");
        if (outfile.IsOpen()==true)
            std::string txt1("Foo\n");
            std::string txt2("Bar\n");
        } else std::cout << "could not open file for writing\n";
Reading would start something like :

        WDL_FileRead infile("C:\\ssd_tests\\wdl_test_file.txt");
        if (infile.IsOpen()==true)
            std::vector<char> buffer(infile.GetSize()+1); // +1 to have space for the terminating zero
            buffer[infile.GetSize()]='\0'; // put in the string terminating zero
But I think I will leave the rest (parsing newlines etc) as an exercise for the reader...(No pun intended.)

If you need to handle text files, perhaps the C++ standard library facilities might be worth looking into again, after all...What kinds of problems did you encounter while trying to use them? (My own pains with ifstream and ofstream have mostly been when trying to use them for binary files, such as wav-files etc...For text files they may work tolerably enough.)
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
Xenakios blog (about HourGlass, Paul(X)Stretch and λ) :

Last edited by Xenakios; 05-06-2014 at 12:00 PM.
Xenakios is online now   Reply With Quote