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?
Printable View
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);
>>I am trying to use ifstream
I guess you want the C++ forum then! Moving thread...
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;
thanks ILoveVectors that is exatley what I was looking for.
thanks for every one elses help to.