+ 2
Saving values between running code?
Using c++ in the code playground is there any way to save values of a variable from one compilation of the code to another? Is this one of the limitations of the code playground?
3 Antworten
+ 11
no, I don't think you can do that.
+ 11
well, I think the only way to do that is by saving the data in the internet. Some people did it. Here are some examples:
https://code.sololearn.com/W7uillQ88Y8l/?ref=app
https://code.sololearn.com/WtFXsv7tdPW0/?ref=app
+ 2
I'm not sure where a filestream would save to when you use it on the c++ playground. I tried using an output file stream, and I didn't get any errors, but when I tried to access the same file name with an input file stream, it wouldn't open it. This leads me to believe it's not really possible to save values this way with c++ in the playground. Here is the code I used to test it:
#include <fstream>
#include <iostream>
using namespace std;
int main() {
ofstream out_file("test.txt");
if (out_file.is_open()) {
out_file << "Why hello there!\n";
out_file << "Does this work?\n";
out_file.close();
} else {
cout << "test.txt could not be opened." << endl;
}
return 0;
}