I am currently working on an assignment and I am trying to figure out a way to output into a file without using file adress as a function parameter since I am not very good at pointers and this function I am going to declare is going to be used in a class. But however, when I try to build the sample function in a new project I created, I get the error "The system cannot find the file specified". I have tried to clean solution and then rebuild it, build failed and when I tried to run, I still got the same error. Here is my function simplified:
#include <iostream>
#include <fstream>
using namespace std;
int main() {
void Export(int data) {
ofstream out("structures_initial.txt");
out << data << endl;
return;
}
for (int i = 0; i < 10; i++) { //I declared i's type but still the same
Export(i);
}
return 0;
}
I am not sure what causes this error and I was wondering that does my function Export make sense? As I think, calling ofstream should not try to create a new output file and it should open the current one and write but I cannot check because of this error probably because I did something wrong (looked up for this error on the internet and there are just so many different reasons for it, I couldn't fix since I couldn't see the issue in my code). I would be glad if you could help me to fix this problem.