Reputation: 7
I've simply put the line to print to the file inside a for loop in order print it five times yet nothing is being printed. My code is as follows:
int main() {
ofstream (fileAccess);
fileAccess.open ("fileName.txt", ofstream::app);
for (int i; i < 5; i++) {
fileAccess << "Hello World!";
}
fileAccess.close();
}
Please help
Upvotes: -1
Views: 112
Reputation: 7
Thanks to Richard Critten, I just had to initialize int i as 0. I've never had this issue before as it usually sets it to 0 by default but I changed that and it worked first try.
Upvotes: 0