Usually when the file name is "example.txt", I can use the following code to read from the file.
string line;
ifstream myfile ("example.txt");
if (myfile.is_open())
{
while ( getline (myfile,line) )
{
cout << line << '\n';
}
myfile.close();
}
else cout << "Unable to open file";
But how can I use the same program to read a file, When the file name is example_201703031140.txt or example_201703031142.txt. (Let's just say this file is the only file in the location with that prefix. In other words, the location can have either example_201703031140.txt OR example_201703031142.txt, not the both )
To clarify the question more, how can I write a program to which can read dynamically changing file names? For example imagine a scenario that I have to write to file which is named example_timestamp and read that file from a separate module (which do not have access to the full file name, but knows that it has a prefix "example" followed by a timestamp)
Update: You do not know what the timestamp is, you just know that it is a timestamp.