Tuesday, June 28, 2005

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!!


completely-complete said...

Terrific blog. I search the internet everytime I
get a moment to find blogs. Its better than cold iced
tea and I have to visit it one more time!
I wish I was like you, but I'll go and peep your 1800contacts com coupon blog.

Cash Till Payday Loan In Atlanta Ga said...

Hot blog. When I get to seraching on the web for
blogs, its got to be like yours! And the site is off
the hook! I just kept coming back!
Search for my 1800contacts coupon codes blog, it will leave you speechless.

Cash Till Payday Loan said...

Nice blog. I seen the site and I adored the work,
that I want to visit it more each day! I like
searching for blogs that have the same content like
this one!
I hope you had a chance to check out my blog.

Instant Cash Loan Till Payday Com said...

Hype blog. And I admire your site and plan on
returning to it! When I web surf it always helps me to
find great blogs.
Hey playa! You need to check out my 1800contacts com coupon blog.

outa-time said...

Fine blog. I found your site suitable for another
visit! And when I'm able to surf the web, I look for
blogs as great as your work.
Click on my coupon 1800contacts blog before its to late.

stunned said...

Fine blog. I found your site suitable for another
visit! And when I'm able to surf the web, I look for
blogs as great as your work.
Hey son, you need to check out my coupon 1800contacts blog!

final fantasy 10 musicd said...

Incredible blog. I admired your site and I will be
back once again to view it! I use much of my spare
time searching for blogs like yours.
In an efford of finding the right info, check for my blog site.

Asset Search said...

Inspiring blog. I love finding blogs this good on
the internet, when I have the time. I'm going to go
back to it!
Search for my coupon codes 1800contacts blog, please!

job opportunitya said...

I surf the web looking for blogs like this one.
Your site was on point and will be back again! Awesome
If your look to uncover information, please visit my plastic surgery gone wrong blog

job opportunitya said...

Fascinating blog. I loved the site you did a good
job on it, I will be back! I surf the net for blog
like this one.
Please proceed to my plastic surgery dallas blog when you find the time.

job opportunitya said...

I took pleasure in the site and I will go back!
Surfing online for blogs like this one is worth my
time. Sensational blog.
Please discover my plastic surgery thailand blog.

Anonymous said...

For solution 2 you don't need the stringstream. You can directly:

ifstream ifs("circle.cc");
cout << ifs.rdbuf();

manho valentine said...

Hello Guy
I think that Keep posting more informative articles like these one.
These are very good articles to visit...
golden slot mobile