I am trying to use ifstream and I have the file location
"c:\\text.txt" saved into a string text and want to have ifstream load the file loaction and name from that string
is that possible?
I am trying to use ifstream and I have the file location
"c:\\text.txt" saved into a string text and want to have ifstream load the file loaction and name from that string
is that possible?
I think you have the wrong forum. ifstream is C++.
In C:
Code:FILE *fp; char str[] = "text.txt"; fp = fopen(str,"r"); //do stuff fclose(fp);
In C++:
I think that will work.Code:ifstream i("c:\\test.txt"); string s; i >> s; ifstream file(s);
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
>>I am trying to use ifstream
I guess you want the C++ forum then! Moving thread...
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
s.c_str() you mean right?
I know this part
ifstream a_file ("c:\\text.txt");
a_file>>str;
cout<<str;
but instead of having "c:\\text.txt" I need to replace it with
string result;
so it would be like this
ifstream a_file (result);
a_file>>str;
cout<<str;
if that explains it better
thanks for the help so far
Code:string filename; string info; cout << "Enter file name! : "; getline(cin, filename, '\n'); ifstream in(filename.c_str()); in >> info; //or getline(in, info, '\n); in.close(); cout << info << endl;
Last edited by ILoveVectors; 07-14-2005 at 06:40 PM.
thanks ILoveVectors that is exatley what I was looking for.
thanks for every one elses help to.