So ifstream is part of the C++ string containers/classes and afaik, char is a C type, so why does is it ,
and not,Code:ifstream fileToOpen fileToOpen.open(const char*);
Code:ifstream fileToOpen fileToOpen.open(string);
So ifstream is part of the C++ string containers/classes and afaik, char is a C type, so why does is it ,
and not,Code:ifstream fileToOpen fileToOpen.open(const char*);
Code:ifstream fileToOpen fileToOpen.open(string);
The more basic type is char*, which can be used with std::string like this:
If it was only possible with a std::string then you couldn't use a plain old C-style string.Code:std::string s = "myfile"; std::ifstream ifs; ifs.open(s.c_str());
However, in C++11 the function is overloaded to allow a std::string or a C-style string.
The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss
C++11 adds an overload that takes a std::string. you're likely using an older compiler, or you're not enabling the features of C++11. if you're using GCC/G++ 4.4 or above, you can add the compiler switch -std=c++0x or -std=c++11 (depending on the version of the compiler), and you should be able to use std::string for this. I'm not sure about other compilers, as I have little or no experience with them.
What can this strange device be?
When I touch it, it gives forth a sound
It's got wires that vibrate and give music
What can this thing be that I found?
If I remember correctly it had more to do with timing. I believe the std::string class, as we know it today, was a late addition to the standard process.Could be historical,
Jim