473,385 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

help me? About "include files"

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
6 4278
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
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
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

"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: steve | last post by:
I am quite frustrated with php抯 include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don抰 get)? The path in include is...
2
by: steve | last post by:
Hi, I need to do conditional script "include", but like to pull the code from db instead of a file. How do I do that? Reason: I like to implement some complex regex logic, and make it table...
7
by: mescaline | last post by:
Hi, Suppose a_file.cpp contains a function a_function() Now to include it in main_file.cpp I just do #include "a_file.cpp" and I'm all set. i recently came across this seemingly roundabout...
4
by: Exits Funnel | last post by:
Hello, I'm slightly confused about when to use parens around #included files and when to use angle brackets. I understand (I think) that the difference is that the compiler will search in its...
18
by: Tuckers | last post by:
My question is, if I have created my own library which lives in its own install directory, to refer to its header file is it better to use #include "MyLibrary.h" or #include <MyLibrary.h> ...
4
by: bibsoconner | last post by:
Hi, I hope someone can please help me. I'm having a lot of trouble with schema files in .NET. I have produced a very simple example that uses "include" to include other schema files. It all...
2
by: Susan Baker | last post by:
Hi, I am (trying) to compile some code I downloaded from the internet. The sources contain references to header files - using the form : #include <pathname/file> If I change the form to...
7
by: Matt Jensen | last post by:
Howdy I want to simulate with .Net what I used to do with classic ASP where you would have a series of include files with utility functions that you would include when you needed them. I read...
1
by: Andrew | last post by:
Hello, friends, In ASP, we use <!-- include --> to include header/footer files. What are recommended to do in ASP.net? Any sample source code or reference papers? Thanks a lot for your help.
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.