473,487 Members | 2,474 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

linux c++ error: ‘ostream’ does not name a type

1 New Member
when I compile it :
hxjnsq@hxjnsq-VirtualBox:~$ g++ stat.cc
stat.cc:19:11: error: ‘ostream’ does not name a type
stat.cc:49:1: error: ‘ostream’ does not name a type
stat.cc: In function ‘int main(int, char**)’:
stat.cc:100:1: error: ‘cerr’ was not declared in this scope
stat.cc:104:1: error: ‘cout’ was not declared in this scope

I don't know why?
Expand|Select|Wrap|Line Numbers
  1. //stat.cc
  2. #include<iostream>
  3. #include<string.h>
  4. #include<errno.h>
  5. #include<sys/types.h>
  6. #include<sys/stat.h>
  7. #include<ostream>
  8. class Stat : public stat
  9. {
  10.  private: 
  11.    char *path;
  12.    int fd;
  13. public:
  14.    Stat(){path=0;fd=-1;}
  15.    ~Stat();
  16.    Stat & examine(const char *pathname);
  17.    Stat & examine(int fd);
  18.    int operator==(Stat &o);
  19.  
  20.    friend ostream & operator<<(ostream &out , Stat &o);
  21. };
  22.  
  23. Stat::~Stat()
  24. {
  25. if(path)
  26.   delete path;
  27. }
  28. Stat & Stat::examine(const char *pathname)
  29. {
  30.    if(path)
  31.       delete path;
  32.    path=strdup(pathname);
  33.    fd=-1;
  34.    if(::stat(path,this)==-1)
  35.       throw errno;
  36.    return *this;
  37. }
  38. Stat & Stat::examine(int fd)
  39. {
  40.  if(path)
  41. {
  42.  delete path;
  43.  path=0;
  44. }
  45. this->fd=fd;
  46. if(::fstat(fd,this)==-1)
  47.   throw errno;
  48. return *this;
  49. }
  50. ostream & operator<<(ostream &out , Stat &o)
  51. {
  52. if(o.fd==-1&&!o.path)
  53. {
  54. out<<"No current infomation."
  55. return out;
  56. }
  57. if(o.path)
  58.   cout<<"stat("<<o.path<<"){\n";
  59. else
  60.   cout<<"fstat("<<o.fd<<"){\n";
  61. cout<<"\tst_dev=\t"<<o.st_dev<<";\n"
  62. <<"\tst_ino=\t"<<o.st_ino<<";\n";
  63.  
  64. cout.setf(ios::oct,ios::basefield);
  65. cout<<"\tst_mode=\t"<<'0'<<o.st_mode<<";\n";
  66.  
  67. cout.setf(ios::dec,ios::basefield);
  68. cout<<"\tst_nlink=\t"<<o.st_nlink<<";\n"
  69. <<"\tst_uid=\t"<<o.st_uid<<";\n"
  70. <<"\tst_gid=\t"<<o.st_gid<<";\n"
  71. <<"\tst_rdev=\t"<<o.st_rdev<<";\n"
  72. <<"\tst_atime=\t"<<o.st_atime<<";\n";
  73. return out;
  74. }
  75. int Stat::operator==(Stat &o)
  76. {
  77. if(fd==-1&&!path)
  78. throw EINVAL;
  79. if(o.fd==-1 && !o.path)
  80. throw EINVAL;
  81.  
  82. if(o.st_dev!=st_dev || o.st_ino!=st_ino)
  83. return 0;
  84.  
  85. return 1;
  86. }
  87.  
  88. int main(int argc,char **argv)
  89. {
  90.   int x;
  91.   Stat t;
  92.   Stat s;
  93.   t.examine("./stat");
  94.  
  95.   for(x=1;x<argc;++x)
  96.      {
  97. try{
  98. s.examine(argv[x]);
  99. }catch(int e)
  100. {
  101. cerr<<strerror(e)<<":stat(2) of"
  102. <<argv[x]<<"\n";
  103. continue;
  104. }
  105. cout<<s<<"\n";
  106.  
  107. cout<<"'"<<argv[x]<<"' is"
  108. <<(s==t?"same":"not the same")
  109. <<"file as ./stat\n";
  110. }
  111. return 0;
  112. }
  113.  
Aug 31 '11 #1
1 16237
weaknessforcats
9,208 Recognized Expert Moderator Expert
You need to add using namespace std.
Aug 31 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1998
by: Liam3 | last post by:
I'm having a problem with a table that accidently had a column added whose type is the same as the table. This is seriously creating a problem as I cannot delete the table and I really don't have...
0
1666
by: Danny Pressley | last post by:
I have a VS.NET 2003 Visual C++ MFC Application Project in which I added a new resource file, I then added an icon to this new resource file and did a rebuild and got the following error: "fatal...
11
13073
by: Danny Pressley | last post by:
I have a VS.NET 2003 Visual C++ MFC Application Project in which I added a new resource file, I then added an icon to this new resource file and did a rebuild and got the following error: "fatal...
7
3500
by: Együd Csaba | last post by:
Hi, I've a problem with some of my stored procs. My config is: RH7.1, Postgres 7.3.2 I had converted a few fields of a few tables from one type to another and after this I made all the...
4
4013
by: Ondrej Spanel | last post by:
The code below does not compile with .NET 2003, I get folowing error: w:\c\Pokusy\delegTemplArg\delegTemplArg.cpp(11) : error C2993: 'float' : illegal type for non-type template parameter 'x' ...
1
13360
by: dotNetDave | last post by:
I keep getting the following error on one of my web service pages: Parser Error Parser Error Message: Could not create type 'SyPixx.Web.ClearService.ConfigureAlarms'. Source Error: Line 1: ...
0
3234
by: WebDev2 | last post by:
I can't get AJAX.NET Pro to work. I keep getting a Compiler Error Message: CS0246: The type or namespace name 'AjaxPro' could not be found (are you missing a using directive or an assembly...
2
14724
by: paul.dunstone | last post by:
HI all I am using msbuild to compile my web application project. After building the solution I get the following error message: Server Error in '/Community' Application....
4
23826
by: infinetinc | last post by:
I'm receiving the following error when this site is published to the production environment: Compiler Error Message: CS0246: The type or namespace name 'GridViewHelper' could not be found (are you...
3
18206
by: mahmoodn | last post by:
Hi, I have a struct with this definition struct SeverityAction : public Action { uint32_t theSeverity; //***** public: SeverityAction(uint32_t aSeverity); ... };
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7132
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7180
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7341
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5439
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4870
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.