Hello i have been coding for about 3 days and i wrote this code. I it runs, it creates file on desktop, but it does not read from it.:confused:
Thank you!
Thank you!
Code:
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
int main() {
ofstream ofile;
ifstream ifile;
string filehold;
vector<string> data;
ofile.open("C:/Users/Me/Desktop/data.txt");
ofile << "ph4n70m";
ifile.open("C:/Users/Me/Desktop/data.txt");
if (ifile.fail()) {
cerr << "Error!" << endl;
exit(true);
}
while (!ifile.eof()) {
ifile >> filehold;
data.push_back(filehold);
}
cout << "data.txt: " << endl;
for (unsigned int i = 0; i < data.size(); i++) {
cout << data[i] << endl;
}
ifile.close();
ofile.close();
system("pause");
return 0;
}