If statements?

Hello Brilliant C++'ers!

I am attempting to make life easier on myself, but pulling my hair out in the effort.

Here is what I would like to do... I would like the program to look for a text file in the folder and read information from that text file. That is no problem. However, if the program does not find the file name, I would like to allow for user inputs. I can get get each of these parts to work individually, but not together. I am attempting to us an 'if' statement to make this work.

Here is my code:

...
infile.open ("Fwd.par");

if(!infile)
{
std::cout << "*********" << endl;
std::cout << "**No parameter file was found.**" << endl;
std::cout << "Enter the name of the parameter file " << endl;
std::cin.getline(parfile,128);
std::cout << endl;

infile.open (parfile);
}

infile >> epainpfile;
infile >> eparptfile;
... (etc.)

Any help you might be able to provide would be GREATLY appreciated! Note that if the parameter file is found (fwd.par) the program goes off without a hitch. Otherwise, I am able to input a parameter file, but the program does not seem to read it.

Thanks!
closed account (zwA4jE8b)
so are you wanting the user to input something like "C:\directory\files\Fwd.par" ?

1
2
3
char namebuf[128];
std::cin.getline(namebuf, 128, '\n');
std::ifstream _inf(namebuf, std::ios::binary);

maybe you don't need std::ios::binary
std::ios::in for your needs
Last edited on
Topic archived. No new replies allowed.