Since you use the standard library (cout
) why not use string
instead of char*
?
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
fstream level;
level.open("level.txt");
string row;
int i = 0;
string data[3];
while ((i<3) && (level >> row)) {
data[i] = row;
cout << i << " " << data[i] << "\n";
i++;
}
for (i = 0; i < 3; i++) {
cout << "\n " << i << " = " << data[i];
}
level.close();