Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Why do I have t...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 43858 of 47926
Post > Topic >>

Why do I have to prefix stat from <sys/stat.h> with the keyword struct?

by Rolf =?UTF-8?B?S3LDvGdlcg==?= <rolf-krueger@[EMAIL PROTECTED] > Mar 12, 2008 at 11:19 PM

Hi


I´m about learning C/C++ and after covering the language basics I´m now
heading for my first "real" application where I need to use the POSIX
stuff
for directory operations.

Here´s my problem: The following code compiles and runs as it should
inside
a linux g++ environment using code::blocks IDE. But when I drop
the "struct" prefix from line 12 "struct stat st;" It doesn´t compile any
more and it says:

|12|error: expected `;' before ‘st’
|12|warning: statement is a reference, not call, to function ‘stat’
|12|warning: statement has no effect
|18|error: ‘st’ was not declared in this scope

Hmm, what´s going on here? Why can I drop "struct" from line 1? IMHO
dirent
is just a struct as stat is. A similar behaviour can be found using the
cygwin environment under windows, so I guess it has nothing to do with
system dependent header files.


Any ideas?
Thanx in advance
Rolf



#include <iostream>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>

using namespace std;

int main() {

    dirent *entry;
    struct stat st;

    DIR *base;
    base = opendir(".");

    while( (entry = readdir(base)) != 0) {
        stat(entry->d_name, &st);
        cout << entry->d_name << " :: " << st.st_mode  << endl;
    }

    closedir(base);

    return 0;
}
 




 3 Posts in Topic:
Why do I have to prefix stat from with the keyword
Rolf =?UTF-8?B?S3LDvGdlcg  2008-03-12 23:19:01 
Re: Why do I have to prefix stat from with the keyw
Ian Collins <ian-news@  2008-03-13 11:38:19 
Re: Why do I have to prefix stat from with the keyw
Rolf =?UTF-8?B?S3LDvGdlcg  2008-03-12 23:35:47 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 6 18:25:10 CDT 2008.