0

I wanted to know how I can print out a filename with fstream into another file. For example:

#include<iostream>
#include<fstream>
#include<string>

using namespace std;

int main(int argc, char *argv[])
{
    string file;   

    ifstream myFile(file);

    cout << "File: " << file << endl;
}

If i had another .cpp file , how can i print " file " in that also.

Borgleader
  • 15,826
  • 5
  • 46
  • 62
  • Have you read this? [previous stackoverflow question](https://stackoverflow.com/questions/10773391/getting-filename-or-path-from-fstream) – pastaleg Nov 13 '17 at 01:48
  • 1
    I'm not sure what youre asking. You seem to be asking how to print something with an fstream but the last line there says "if i had another .cpp file" so I'm a bit confused. Can you clarify what exactly it is youre trying to achieve? – Borgleader Nov 13 '17 at 01:50

1 Answers1

0

'file' is typed as a 'string' but you don't initiate it. so when you create an ifstream object called 'myFile' and associate it with the file 'file', it will not know what to do, because 'file' has no file name (or string) in it.

Joel
  • 197
  • 1
  • 10