Why does the following code not work
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
int main(){
string data;
int i=0;
while(i <= 5){
i++;
data += i;
data += "\n";
}
ofstream myfile;
myfile.open ("data.txt");
myfile << data;
myfile.close();
}
It should append a number then newline and write it to a file (that doesn't yet exist).
The file should look like this...
1
2
3
4
5
What is wrong with the code?