Search code examples
c++fileonline-compilation

Online CPP Compiler that allows writing/reading


I am trying to write out data and read it back in on ideone.com. I could not figure it out:

ofstream os ("data.dat", ios::binary);

did not work, when I try to read back in with

ifstream is("data.dat", ios::binary);

the size of the data read is 0.

Is there a different syntax at online compilers, such as ideone.com?


Solution

  • Most if not all online compilers that I have seen do not allow you to read and write to files. Most allow you to input text into an input box and then they redirect the standard input to that box so you can change the input to the program from run to run.

    Reading this answer by Shafik Yaghmour and the attached documentation it looks like you can create a file with coliru and then use that file in a subsequent program but I have no idea how well that will work with a binary file and it looks like it might be read only.

    I would think most services do want to allow file uploads as then people could upload to there service and then the site could be hosting some undesirable content.

    If you need to work with files I suggest you use an actual compiler on your PC. If you need something that is free then you can start at Bjarne Stroustrup's An incomplete list of C++ compilers