I'm more of a C guy. What's the idiomatic C++11 or 14 way of doing this?
This looks like the most correct answer. Thanks.
So basically all that refactoring and work produced no discernible advantage. Nice to know.
You're welcome. Keep in mind, while the std::ifstream won't be initialized unless needed, space for the object will still be reserved on the stack in main(). If you really must avoid stack allocation altogether, use this one: . (but remember to check for allocation failure before dereferenceing, unlike the example).
if (!fin || !*fin) return 1;.
the general idea is that the software is safer and easier to work with, while losing no speed. So you can apply new optimizations in the future, or add on new features, that you would have had to avoid if you'd stuck with C.
The problem with this idea is that Rust is harder to work with than C.
What are you trying to do OP, simply dump the contents of a textfile?#include #include #include int main() { std::string filename{"FooBar.txt"}, line{}; std::ifstream ifs{filename}; while (std::getline(ifs, line)) std::cout