I am relatively new to C++ and are trying to write a function reads text file and saves/returns the resulting data as data structure.'
I have an issue that the main(), function is executing the one I provided - anyone know how I can fix that?
#include <iostream>
#include <fstream>
using namespace std;
int readPricesFromFile () {
fstream my_file;
my_file.open("clean100.txt", ios::in);
if (!my_file) {
cout << "No such file";
}
else {
char ch;
while (1) {
my_file >> ch;
if (my_file.eof())
break;
cout << ch << endl;
}
}
my_file.close();
return 0;
}
int main() {
int readPricesFromFile ();
}
In this case I have to call a function that reads and writes a fail, but I am confused on how to do it.