File handling in G++

 I want to know the syntax for initializing a stream for input using g++.
What's wrong with:

ifstream fin;"Myfile.txt");

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

I would suggest

#include <fstream>
using namespace std; // probably you forgot to specify the namespace usage

fstream fin("Myfile.txt", ios_base::in);
If you insist on using ifstream then

using namespace std;

ifstream fin;"Myfile.txt");

using std::ifstream;

ifstream fin;"Myfile.txt");

What error do you receive ?
A compilation error or a runtime error ?
For a runtime error look where you put the file ..

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
I recommend using prefix, instead of adding the type to the global namespace.


std::ifstream fin;  //Put std:: in front"Myfile.txt");
I think that both axter and myself gave a solution.
I recommend a split
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.