LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   'fstream' does not name a type (https://www.linuxquestions.org/questions/programming-9/fstream-does-not-name-a-type-847187/)

harishisnow 11-29-2010 05:39 AM

'fstream' does not name a type
 
Hello,
I have included fstream in my file (#include <fstream>)
In the file, I have a class declaration and a private variable
static fstream fileStopWatch ;
Then I am getting the error "'fstream' does not name a type"
It was working in gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)
but not working in gcc version 4.4.4 (GCC)

ex:
class Utility
{
..
..
private:
static fstream fileStopWatch ;
..
..
};
Please suggest a solution for the above problem.

Regards,
Harish

neonsignal 11-29-2010 06:56 AM

The error means that it cannot find a type named fstream. This is happening because fstream is in the std namespace. Try the following instead:
Code:

class Utility
{
..
..
private:
static std::fstream fileStopWatch ;
..
..
};

However, this change (not polluting the global namespace) happened around the 3.x series of gcc. There are also some minor changes in the requirements on scoping of the standard library as we move towards C++0x.

harishisnow 11-30-2010 12:12 AM

Hello,
Thanks a lot for your response.
The change worked.
Regards,
Harish


All times are GMT -5. The time now is 11:59 PM.