Hey,
I am making a program where the user is asked what filename he wants to open.
This is what I have:
cout<<"Enter File Name"<<endl;
cin>>filename;
ifstream inl(filename.txt);
What do I need?
Thanks
Hey,
I am making a program where the user is asked what filename he wants to open.
This is what I have:
cout<<"Enter File Name"<<endl;
cin>>filename;
ifstream inl(filename.txt);
What do I need?
Thanks
i could be wrong but i believe the ifstream constructor takes a c-string (char*). so you would have to have
string::c_str() returns its c-string counterpart.Code:cout<<"Enter File Name"<<endl; cin>>filename; ifstream inl(filename.c_str());
you are right... he can also do this
...
char str[30];
cout << "Filename";
cin >> str;
ifstream ins;
ins.open(str);
...
>>>ifstream inl(filename.txt);
oh... and the .txt part doesn't work like that. That wouldn't compile.
Blue
it would work if "txt" was a variable inside the structure "filename" but it isn't, so ya, it wouldn't compile.
When I first glanced I thought all you was trying to do was open a file named filename.txt.