help me? About "include files"

W

wukexin

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 * *)
 
K

Kevin Goodsell

wukexin said:
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
 
D

David Harmon

help.h
//--------------------------------------------------------------------------
#ifndef helpH
#define helpH

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

#include said:
namespace myhelp
{
void print(const string x);

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

wukexin

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.
 
S

Sharad Kala

wukexin said:
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
 
W

wukexin

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 said:
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 * *)
 
K

Kevin Goodsell

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 said:
namespace Myhelp
{
void print(const std::string& x);
}
//--------------------------------------------------------------------------
-
#endif
//////////////////////////////////////////////

-Kevin
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top