Why this should not work?
Why fstream doesn't accept a string as a path?Code:#include <iostream> #include <fstream> #include <string> int main() { using namespace std; string str = "C:\\test.del"; ifstream f(str); }
Why this should not work?
Why fstream doesn't accept a string as a path?Code:#include <iostream> #include <fstream> #include <string> int main() { using namespace std; string str = "C:\\test.del"; ifstream f(str); }
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
fstreams take a const char* as the filename, so you have to call c_str() on the string to pass it to the fstream constructor or open function.
I know that, but it is wrong.fstreams take a const char* as the filename, so you have to call c_str() on the string to pass it to the fstream constructor or open function.
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
You mean that you think they should change it? They might change it in the next standard. In the previous standard, fstreams were already widely used before the string class was created.
I agree that there should be an overload for strings, but I don't think its that big of a deal.
The much bigger problem with fstream is the lack of any way to provide a wchar_t pathname.
That means WinNT systems can't express pathnames in the native character set of their machine, and thus it's impossible in standard C++ to open all possible filenames (you need to use WinAPI file handling in lieu of C++ streams).
You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.
Of course they should change it. Because at least standard library should support itself. It is now contrary to what Stroustrup has in mind.You mean that you think they should change it? They might change it in the next standard.
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C