Reading data from a txt file

Hi I was trying to create a program that reads data in a txt file and produces it.
My problem is that the output keeps closing, I'm not sure if my code is wrong or if I just didn't add something to keep the console open. It would be great if one of you could help me, here is what I have so far.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  #include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <stdio.h>
using namespace std;

int main ()
{
    string filename = "info.dat";
    string line;
    ifstream inFile;
    
    inFile.open(filename.c_str());
    
    if (inFile.fail()) 
    {
                       cout << "\nThe file was not successfully opened"
                            << "\n Please check that the file currently exists."
                            << endl;
                            exit(1);
                            }
                            inFile.close();
                            std::cin.get(); 
                            return 0;
                            }
Maybe it just could not open the file and your eror hadling routine was executed? What is the return code?
Well there isn't really any return code the console just automatically closes
Do you run it from IDE? It should report return code for you.
Try to pause before exiting program in cause of error
Actually I figured it out, I had to change the file name in order to do it.

Thank you for your effort though
Topic archived. No new replies allowed.