Reading entire file in one go.
Solution 1:
std::ifstream in("circle.cc");
std::istreambuf_iterator < char > begin(in), end;
std::string str(begin, end);
Solution 2:
std::ifstream input("circle.cc");
std::ostringstream temp;
temp << input.rdbuf();
std::string str = temp.str();
In both the cases,
std::cout << str;
will print out entire file.
Perl solution:
open CIRCLE, "circle.cc";
@mylist = <CIRCLE> ;
close CIRCLE;
C++ and Perl both take 3 lines of code.
Not bad for a system programming language!!
Solution 1:
std::ifstream in("circle.cc");
std::istreambuf_iterator < char > begin(in), end;
std::string str(begin, end);
Solution 2:
std::ifstream input("circle.cc");
std::ostringstream temp;
temp << input.rdbuf();
std::string str = temp.str();
In both the cases,
std::cout << str;
will print out entire file.
Perl solution:
open CIRCLE, "circle.cc";
@mylist = <CIRCLE> ;
close CIRCLE;
C++ and Perl both take 3 lines of code.
Not bad for a system programming language!!
Comments
ifstream ifs("circle.cc");
cout << ifs.rdbuf();
Hello Guy
I think that Keep posting more informative articles like these one.
These are very good articles to visit...
golden slot mobile