help me? About "include files"

Discussion in 'C++' started by wukexin, Jan 26, 2004.

  1. wukexin

    wukexin Guest

    Help me, good men. I find mang books that introduce bit "mang header
    files",they talk too bit,in fact it is my too fool, I don't learn it, I have
    do a test program, but I have no correct doing result in any way. Who can
    help me, I thank you very very much.

    list.cpp(main program)
    //--------------------------------------------------------------------------
    -
    #pragma hdrstop
    #pragma argsused
    #include <string>
    #include <vector>
    #include <iostream>
    #include <algorithm>
    #include "help.h"
    #include "file.h"
    using namespace std;
    int main(int argc, char* argv[])
    {
    int number=argc;
    if(number<1)
    {
    cout<<"The program run program!"<<endl;
    return 0;
    }
    vector<string> option;
    for(unsigned i=1;i<argc;i++)
    {
    option.push_back(argv);
    }
    sort(option.begin(),option.end());
    //for_each(option.begin()),option.end(),myhelp::print);
    vector<string> filename,pathname;
    for(unsigned i=0;i<option.size();i++)
    {
    using namespace myfile;
    if( is_dir(option) )
    {
    pathname.push_back(option);
    }
    }
    for(unsigned i=0;i<option.size();i++)
    {
    using namespace myfile;
    print(option);
    }
    return 0;
    }
    ////////////////////////////////////////////////////////////////////////////
    /
    file.h:
    //--------------------------------------------------------------------------
    -
    #ifndef fileH
    #define fileH
    namespace myfile
    {
    using namespace std;
    bool is_dir(const string x);
    };
    #endif
    ////////////////////////////////////////////////////////////////////////////
    /
    file.cpp
    //--------------------------------------------------------------------------
    -
    #include <dir.h>
    #ifdef fileH
    #define fileH
    #endif
    #include <string>
    using namespace std;
    bool is_dir(const string x)
    {
    struct ffblk file;
    int done=findfirst(x.c_str(),&file,FA_DIREC);
    bool result(false);
    if(0==done)
    {
    result=true;
    }
    else
    {
    result=false;
    }
    return result;
    }
    ////////////////////////////////////////////////////////////////////////////
    //
    help.h
    //--------------------------------------------------------------------------
    -
    #ifndef helpH
    #define helpH
    namespace myhelp
    {
    void print(const string x);
    };
    #endif
    ////////////////////////////////////////////////////////////////////////////
    /
    help.cpp
    //--------------------------------------------------------------------------
    -
    #pragma hdrstop
    #include "help.h"
    #include <string>
    #include <iostream>
    using namespace std;
    void print(const string x)
    {
    cout<<x<<endl;
    }
    ////////////////////////////////////////////////////////////////////////////
    /
    ÕâÊDZàÒë½á¹û:
    [C++ Error] help.h(6): E2293 ) expected
    Full parser context
    list.cpp(7): #include D:\PROGRAM\WUKEXIN\FILE\help.h
    help.h(5): namespace myhelp
    [C++ Warning] list.cpp(19): W8012 Comparing signed and unsigned values
    Full parser context
    list.cpp(11): parsing: int cdecl main(int,char * *)
    [C++ Error] list.cpp(37): E2268 Call to undefined function 'print'
    Full parser context
    list.cpp(11): parsing: int cdecl main(int,char * *)
     
    wukexin, Jan 26, 2004
    #1
    1. Advertising

  2. wukexin wrote:

    > Help me, good men. I find mang books that introduce bit "mang header
    > files",they talk too bit,in fact it is my too fool, I don't learn it, I have
    > do a test program, but I have no correct doing result in any way. Who can
    > help me, I thank you very very much.


    I really don't understand what you are saying.

    >
    > list.cpp(main program)
    > //--------------------------------------------------------------------------
    > -
    > #pragma hdrstop
    > #pragma argsused


    Please leave out the non-standard stuff (like these pragmas) when
    posting here. This group discusses standard C++ only. If we can't
    compile your code because of non-standard constructs, it limits our
    ability to help.

    > #include <string>
    > #include <vector>
    > #include <iostream>
    > #include <algorithm>
    > #include "help.h"
    > #include "file.h"
    > using namespace std;
    > int main(int argc, char* argv[])
    > {
    > int number=argc;
    > if(number<1)
    > {
    > cout<<"The program run program!"<<endl;
    > return 0;
    > }
    > vector<string> option;
    > for(unsigned i=1;i<argc;i++)


    This is probably the cause of one of your warnings. 'i' is unsigned,
    'argc' is signed. This type of comparison can give surprising results in
    some cases, so some compilers warn about it.

    > {
    > option.push_back(argv);
    > }
    > sort(option.begin(),option.end());
    > //for_each(option.begin()),option.end(),myhelp::print);
    > vector<string> filename,pathname;
    > for(unsigned i=0;i<option.size();i++)


    Be warned that some older compilers won't accept this, even though it's
    correct. They will complain that you are redeclaring 'i', because they
    get the scope wrong for variables declared in a 'for' loop init expression.

    > {
    > using namespace myfile;
    > if( is_dir(option) )
    > {
    > pathname.push_back(option);
    > }
    > }
    > for(unsigned i=0;i<option.size();i++)
    > {
    > using namespace myfile;


    You don't seem to be using anything from this namespace. Maybe you
    wanted 'myhelp' instead? That's where the function you use next is
    supposed to be:

    > print(option);
    > }
    > return 0;
    > }
    > ////////////////////////////////////////////////////////////////////////////
    > /
    > file.h:
    > //--------------------------------------------------------------------------
    > -
    > #ifndef fileH
    > #define fileH
    > namespace myfile
    > {
    > using namespace std;
    > bool is_dir(const string x);


    Don't you think that x should be a const reference?

    > };


    No semi-colon at the end of a namespace.

    > #endif
    > ////////////////////////////////////////////////////////////////////////////
    > /
    > file.cpp
    > //--------------------------------------------------------------------------
    > -
    > #include <dir.h>


    This is not a standard header.

    > #ifdef fileH
    > #define fileH
    > #endif


    What are these 3 lines for? It looks like a broken include guard, but we
    don't use include guards for .cpp files. You need to get rid of these,
    and you also need to add

    #include "file.h"

    (Or at least it would be a good idea to add this, even if it's not
    strictly necessary.)

    > #include <string>
    > using namespace std;
    > bool is_dir(const string x)


    Didn't you want this to be myfile::is_dir()?

    > {
    > struct ffblk file;


    Non-standard.

    > int done=findfirst(x.c_str(),&file,FA_DIREC);


    Non-standard.

    > bool result(false);
    > if(0==done)
    > {
    > result=true;
    > }
    > else
    > {
    > result=false;
    > }
    > return result;
    > }
    > ////////////////////////////////////////////////////////////////////////////
    > //
    > help.h
    > //--------------------------------------------------------------------------
    > -
    > #ifndef helpH
    > #define helpH
    > namespace myhelp
    > {
    > void print(const string x);
    > };


    No semi-colon here.

    > #endif
    > ////////////////////////////////////////////////////////////////////////////
    > /
    > help.cpp
    > //--------------------------------------------------------------------------
    > -
    > #pragma hdrstop


    Non-standard.

    > #include "help.h"
    > #include <string>
    > #include <iostream>
    > using namespace std;
    > void print(const string x)


    Didn't you want this to be myhelp::print()? And don't you think x should
    be a const reference?

    > {
    > cout<<x<<endl;
    > }
    > ////////////////////////////////////////////////////////////////////////////
    > /
    > ÕâÊDZàÒë½á¹û:
    > [C++ Error] help.h(6): E2293 ) expected
    > Full parser context
    > list.cpp(7): #include D:\PROGRAM\WUKEXIN\FILE\help.h
    > help.h(5): namespace myhelp


    I don't see where this error came from.

    > [C++ Warning] list.cpp(19): W8012 Comparing signed and unsigned values
    > Full parser context
    > list.cpp(11): parsing: int cdecl main(int,char * *)


    I mentioned the cause of this earlier.

    > [C++ Error] list.cpp(37): E2268 Call to undefined function 'print'
    > Full parser context
    > list.cpp(11): parsing: int cdecl main(int,char * *)


    And this is because there's no function 'print' in scope, probably
    because you 'used' the wrong namespace - 'print' is in 'myhelp', not in
    'myfile'.

    -Kevin
    --
    My email address is valid, but changes periodically.
    To contact me please use the address from a recent posting.
     
    Kevin Goodsell, Jan 26, 2004
    #2
    1. Advertising

  3. wukexin

    David Harmon Guest

    On Mon, 26 Jan 2004 10:43:40 +0800 in comp.lang.c++, "wukexin"
    <> was alleged to have written:
    >help.h
    >//--------------------------------------------------------------------------
    >#ifndef helpH
    >#define helpH


    Below you use 'string' without declaring it. Insert here

    #include <string>

    >namespace myhelp
    >{
    > void print(const string x);


    void print(const std::string &x);

    >};
    >#endif
     
    David Harmon, Jan 26, 2004
    #3
  4. wukexin

    wukexin Guest

    Thank you very much. I mean I don't know how write a program that it include
    many compiler unit. Need you give me a hand.
    If you have a free time, please write a example include many file.cpp and
    file.h. Or you recommend some books, they introduce practical program in
    c++, in fact, real program can't have only one file.cpp and only one file.h.
    I need a particular knowledge about really program. I need your help, thank
    you.

    "David Harmon" <> ????
    news:...
    > On Mon, 26 Jan 2004 10:43:40 +0800 in comp.lang.c++, "wukexin"
    > <> was alleged to have written:
    > >help.h

    >
    >//-------------------------------------------------------------------------

    -
    > >#ifndef helpH
    > >#define helpH

    >
    > Below you use 'string' without declaring it. Insert here
    >
    > #include <string>
    >
    > >namespace myhelp
    > >{
    > > void print(const string x);

    >
    > void print(const std::string &x);
    >
    > >};
    > >#endif

    >
     
    wukexin, Jan 26, 2004
    #4
  5. wukexin

    Sharad Kala Guest

    "wukexin" <> wrote in message news:bv2pfg$cr$99.com...
    > Thank you very much. I mean I don't know how write a program that it include
    > many compiler unit. Need you give me a hand.
    > If you have a free time, please write a example include many file.cpp and
    > file.h. Or you recommend some books, they introduce practical program in
    > c++, in fact, real program can't have only one file.cpp and only one file.h.
    > I need a particular knowledge about really program. I need your help, thank
    > you.


    1. Please don't top-post.
    2. This is a post which I have (shamelessly ;-)) picked from the Usenet archive.
    You must thank Karl for writing such a good post.
    http://makeashorterlink.com/?I68711037

    Best wishes,
    Sharad
     
    Sharad Kala, Jan 26, 2004
    #5
  6. wukexin

    wukexin Guest

    Re: help me? About "include files", wrong, wrong ! Why?

    I need your help, very much. About namespace and using head file. If you
    give me a partical example, I will thank you very much. Thank you,good men.
    my change:
    help.cpp:
    ////////////////////////////////////////////
    #include "help.h"
    #include <iostream>
    #include <string>
    using namespace std;
    namespace Myhelp
    {
    void print(const string& x);
    }
    using namespace Myhelp;
    void print(const string& x)
    {
    cout<<x<<endl;
    }
    /////////////////////////////////////////////

    help.h
    //////////////////////////////////////////////
    //--------------------------------------------------------------------------
    -
    #ifndef helpH
    #define helpH
    namespace Myhelp
    {
    void print(const std::string& x);
    }
    //--------------------------------------------------------------------------
    -
    #endif
    //////////////////////////////////////////////
    error message:(bcb 6.0)
    [C++ Error] help.h(6): E2449 Size of 'print' is unknown or zero
    Full parser context
    help.cpp(1): #include D:\PROGRAM\WUKEXIN\FILE\help.h
    help.h(5): namespace Myhelp
    [C++ Error] help.h(6): E2188 Expression syntax
    Full parser context
    help.cpp(1): #include D:\PROGRAM\WUKEXIN\FILE\help.h
    help.h(5): namespace Myhelp
    [C++ Error] help.h(6): E2293 ) expected
    Full parser context
    help.cpp(1): #include D:\PROGRAM\WUKEXIN\FILE\help.h
    help.h(5): namespace Myhelp
    [C++ Error] help.cpp(7): E2238 Multiple declaration for 'print'
    Full parser context
    help.cpp(6): namespace Myhelp
    [C++ Error] help.h(6): E2344 Earlier declaration of 'print'
    Full parser context
    help.cpp(6): namespace Myhelp
    error message: (mingw)
    In file included from list.cpp:6:
    file.h:8:7: warning: no newline at end of file
    H:\DOCUME~1\MAIGRE~1\LOCALS~1\Temp/cc0saaaa.o(.text+0x2e6):list.cpp:
    undefined r
    eference to `myfile::is_dir(std::string)'
    H:\DOCUME~1\MAIGRE~1\LOCALS~1\Temp/cc0saaaa.o(.text+0x3c1):list.cpp:
    undefined r
    eference to `Myhelp::print(std::string const&)'
    /////////////////////////////////////////////
    "wukexin" <> дÈëÓʼþ news:bv1usq$2n0r$99.com...
    > Help me, good men. I find mang books that introduce bit "mang header
    > files",they talk too bit,in fact it is my too fool, I don't learn it, I

    have
    > do a test program, but I have no correct doing result in any way. Who can
    > help me, I thank you very very much.
    >
    > list.cpp(main program)
    >

    //--------------------------------------------------------------------------
    > -
    > #pragma hdrstop
    > #pragma argsused
    > #include <string>
    > #include <vector>
    > #include <iostream>
    > #include <algorithm>
    > #include "help.h"
    > #include "file.h"
    > using namespace std;
    > int main(int argc, char* argv[])
    > {
    > int number=argc;
    > if(number<1)
    > {
    > cout<<"The program run program!"<<endl;
    > return 0;
    > }
    > vector<string> option;
    > for(unsigned i=1;i<argc;i++)
    > {
    > option.push_back(argv);
    > }
    > sort(option.begin(),option.end());
    > //for_each(option.begin()),option.end(),myhelp::print);
    > vector<string> filename,pathname;
    > for(unsigned i=0;i<option.size();i++)
    > {
    > using namespace myfile;
    > if( is_dir(option) )
    > {
    > pathname.push_back(option);
    > }
    > }
    > for(unsigned i=0;i<option.size();i++)
    > {
    > using namespace myfile;
    > print(option);
    > }
    > return 0;
    > }
    >

    ////////////////////////////////////////////////////////////////////////////
    > /
    > file.h:
    >

    //--------------------------------------------------------------------------
    > -
    > #ifndef fileH
    > #define fileH
    > namespace myfile
    > {
    > using namespace std;
    > bool is_dir(const string x);
    > };
    > #endif
    >

    ////////////////////////////////////////////////////////////////////////////
    > /
    > file.cpp
    >

    //--------------------------------------------------------------------------
    > -
    > #include <dir.h>
    > #ifdef fileH
    > #define fileH
    > #endif
    > #include <string>
    > using namespace std;
    > bool is_dir(const string x)
    > {
    > struct ffblk file;
    > int done=findfirst(x.c_str(),&file,FA_DIREC);
    > bool result(false);
    > if(0==done)
    > {
    > result=true;
    > }
    > else
    > {
    > result=false;
    > }
    > return result;
    > }
    >

    ////////////////////////////////////////////////////////////////////////////
    > //
    > help.h
    >

    //--------------------------------------------------------------------------
    > -
    > #ifndef helpH
    > #define helpH
    > namespace myhelp
    > {
    > void print(const string x);
    > };
    > #endif
    >

    ////////////////////////////////////////////////////////////////////////////
    > /
    > help.cpp
    >

    //--------------------------------------------------------------------------
    > -
    > #pragma hdrstop
    > #include "help.h"
    > #include <string>
    > #include <iostream>
    > using namespace std;
    > void print(const string x)
    > {
    > cout<<x<<endl;
    > }
    >

    ////////////////////////////////////////////////////////////////////////////
    > /
    > ÕâÊDZàÒë½á¹û:
    > [C++ Error] help.h(6): E2293 ) expected
    > Full parser context
    > list.cpp(7): #include D:\PROGRAM\WUKEXIN\FILE\help.h
    > help.h(5): namespace myhelp
    > [C++ Warning] list.cpp(19): W8012 Comparing signed and unsigned values
    > Full parser context
    > list.cpp(11): parsing: int cdecl main(int,char * *)
    > [C++ Error] list.cpp(37): E2268 Call to undefined function 'print'
    > Full parser context
    > list.cpp(11): parsing: int cdecl main(int,char * *)
    >
    >
    >
    >
    >
    >
    >
     
    wukexin, Jan 27, 2004
    #6
  7. Re: help me? About "include files", wrong, wrong ! Why?

    wukexin wrote:

    Please don't top-post. Trim the non-relevant part of the message you are
    replying to, and put the text of your reply *after* the remaining text.

    > I need your help, very much. About namespace and using head file. If you
    > give me a partical example, I will thank you very much. Thank you,good men.
    > my change:
    > help.cpp:
    > ////////////////////////////////////////////
    > #include "help.h"
    > #include <iostream>
    > #include <string>
    > using namespace std;
    > namespace Myhelp
    > {
    > void print(const string& x);
    > }


    Why are you repeating this here? You already have it in help.h.

    > using namespace Myhelp;
    > void print(const string& x)


    Isn't this supposed to be Myhelp::print?

    > {
    > cout<<x<<endl;
    > }
    > /////////////////////////////////////////////
    >
    > help.h
    > //////////////////////////////////////////////
    > //--------------------------------------------------------------------------
    > -
    > #ifndef helpH
    > #define helpH


    You use std::string later, so you need to add

    #include <string>

    > namespace Myhelp
    > {
    > void print(const std::string& x);
    > }
    > //--------------------------------------------------------------------------
    > -
    > #endif
    > //////////////////////////////////////////////


    -Kevin
    --
    My email address is valid, but changes periodically.
    To contact me please use the address from a recent posting.
     
    Kevin Goodsell, Jan 27, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike Laskie

    #include files?

    Mike Laskie, Aug 27, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    2,633
    Mike Laskie
    Sep 2, 2003
  2. daniel kaplan

    include files in perl

    daniel kaplan, Sep 17, 2004, in forum: Perl
    Replies:
    2
    Views:
    7,858
    Windex007
    Dec 18, 2009
  3. Neil Steventon

    include files

    Neil Steventon, Jul 9, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    593
    Kevin Spencer
    Jul 9, 2003
  4. mark
    Replies:
    1
    Views:
    734
    Victor Bazarov
    Jun 19, 2004
  5. Mark

    <!--include files - help

    Mark, Mar 7, 2005, in forum: ASP General
    Replies:
    5
    Views:
    128
    Kyle Peterson
    Apr 30, 2005
Loading...

Share This Page