0

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.

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
alpha01
  • 11
  • 3
  • 1
    Hint: `int readPricesFromFile ();` is a function *declaration* not a function *call*. – tadman Oct 17 '22 at 06:48
  • [Why is iostream::eof inside a loop condition (i.e. `while (!stream.eof())`) considered wrong?](https://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-i-e-while-stream-eof-cons) – Jason Oct 17 '22 at 06:49
  • How to call a function is explained in any [beginner c++ book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – Jason Oct 17 '22 at 06:50

0 Answers0