Input file from command line using '<' operator

I am currently working on a project which requires the program to get the input file from the command line using '<', not from a prompt within the program.  I understand how to get the information out of the file using the std::cin command, but what I was wonder is how I could retrieve the actual filename of the input file that is entered.

>> ./myprog<inputvar.txt

How do I get the name of inputvar to use in my main function?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

>>How do I get the name of inputvar to use in my main function?

You won't need it - just read the input from 'stdin', that's where the shell will direct the contents of the file to.


cin >> InputFromStdIn;


fgets ( InputFromStdIn, stdin);


gets ( InputFromStdIn);
If there is a way to do this at all, it will be platform-specific.  If you specify your target operating system, someone may be able to advise you.
geesh jkr you're too fast 6 mins
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

Ant_DoggAuthor Commented:
I'm using linux.  The problem entails the input file to be entered from the command prompt, playing with the data (I have not problem with this part), and then making an output file using the name of the input file with a suffix on it.  If the input file were test.txt, I would want the output file to be textout.txt, so on and so forth.  Does this make more sense?

You can use on any platform
>> ./myprog<inputvar.txt > inputvarout.txt
and use stdout to write your output.
Ant_DoggAuthor Commented:
That would work except for the fact that I have to generate multiple output files, each with a different suffix on it.  If the input file was input.txt, I would have to make input1.txt, input2.txt, input3.txt.  What I really need to know how to do is how to put the input filename from the command line (via '<') into a string variable.
Since the command line does not contain the part after < could you do the redirection?
./myprog -i inputvar.txt
now you find
inputvar.txt as argv[2] in your main. And it is up to your program to redirect stdin to this file.
Ant_DoggAuthor Commented:
That sounds like it would solve my problem, SteH, however I am having trouble getting the files opened.  Would I code:

      ifstream inFile(argv[2].c_str());          // open input stream

      ofstream outFile(argv[2].var);       //open output stream

No comment has been added lately, so it's time to clean up this question.
I will leave the following recommendation for this question in the Cleanup topic area:

PAQ with points refunded

Please leave any comments here within the next four days.

EE Cleanup Volunteer
PAQed, with points refunded (125)

Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.