#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
usingnamespace std;
int main (){
char filename [50];
ifstream asd;
cin.getline (filename, 50);
asd.open(filename);
//to close the program if txt does not open
if (!asd.is_open()){
exit(EXIT_FAILURE);
}
char word [50];
asd >> word;
while(asd.good()){
cout << word << " ";
asd >> word;
}
system ("pause");
return 0;
}
What you have posted is a fully working program that reads a filename from the user and then opens that file and displays the content. I note that it doesn't prompt for the filename, it just immediately reads the input, so that may be confusing you when you run it - it may seem like it's not doing anything.
But is that what you expect the program to do? If it is, and it's not doing that, can you tell us exactly what the problem is?
If that's not what you expect it to do, what do you think it should be doing?