Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the <iosfwd> header?

What's the <iosfwd> header used for? Why is it necessary?

Any example?

like image 221
wp2 Avatar asked Nov 29 '10 03:11

wp2


1 Answers

It's so you can declare, in your own headers, methods that rely on the declarations of iostream types without having to #include the iostream headers themselves, which are large, complex and slow to compile against.

Here's a simple example:

// foo.h #include <iosfwd>  void sucker(std::iostream& is); 

 

// foo.cc #include <iostream>  void sucker(std::iostream& is) {     is >> somevar; } 
like image 82
Marcelo Cantos Avatar answered Sep 27 '22 21:09

Marcelo Cantos