By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,208 Members | 1,072 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,208 IT Pros & Developers. It's quick & easy.

help me? About "include files"

P: n/a
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[i]);
}
sort(option.begin(),option.end());
//for_each(option.begin()),option.end(),myhelp::prin t);
vector<string> filename,pathname;
for(unsigned i=0;i<option.size();i++)
{
using namespace myfile;
if( is_dir(option[i]) )
{
pathname.push_back(option[i]);
}
}
for(unsigned i=0;i<option.size();i++)
{
using namespace myfile;
print(option[i]);
}
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;
}
////////////////////////////////////////////////////////////////////////////
/
这是编译结果:
[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 * *)



Jul 22 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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[i]);
}
sort(option.begin(),option.end());
//for_each(option.begin()),option.end(),myhelp::prin t);
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[i]) )
{
pathname.push_back(option[i]);
}
}
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[i]);
}
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;
}
////////////////////////////////////////////////////////////////////////////
/
这是编译结果:
[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.
Jul 22 '05 #2

P: n/a
On Mon, 26 Jan 2004 10:43:40 +0800 in comp.lang.c++, "wukexin"
<wu*****@sina.com> 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


Jul 22 '05 #3

P: n/a
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" <so****@netcom.com> ????
news:40****************@news.west.earthlink.net...
On Mon, 26 Jan 2004 10:43:40 +0800 in comp.lang.c++, "wukexin"
<wu*****@sina.com> 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

Jul 22 '05 #4

P: n/a

"wukexin" <wu*****@sina.com> wrote in message news:bv*********@mail.cn99.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
Jul 22 '05 #5

P: n/a
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" <wu*****@sina.com> 写入邮件 news:bv***********@mail.cn99.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[i]);
}
sort(option.begin(),option.end());
//for_each(option.begin()),option.end(),myhelp::prin t);
vector<string> filename,pathname;
for(unsigned i=0;i<option.size();i++)
{
using namespace myfile;
if( is_dir(option[i]) )
{
pathname.push_back(option[i]);
}
}
for(unsigned i=0;i<option.size();i++)
{
using namespace myfile;
print(option[i]);
}
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;
}
//////////////////////////////////////////////////////////////////////////// /
这是编译结果:
[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 * *)


Jul 22 '05 #6

P: n/a
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.
Jul 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.