Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > #include "bar" negates #include <string> ; how to fix?

Reply
Thread Tools

#include "bar" negates #include <string> ; how to fix?

 
 
Danny Anderson
Guest
Posts: n/a
 
      08-15-2003
Hola!

I am working on a program where I am including a library that came with my
numerical methods textbook. The "util.h" simply includes a large number
of files. I had to change the util.h slightly to adjust path names and
also take into account I am working with a case-sensitive OS.

My program is below. The sticky point is that adding (#include "util.h")
seems to negate the (#include <string>) statement somehow. How can I get
around this? For obvious size reasons, I don't include the util.h
library, etc. I did include the compiler error messages below.

As always, thanks!
Danny


//---START CODE---------
/*
* Commenting out the first #include allows for program compilation
* on my Redhat9.0 box using g++ 3.2.2.
*
*/

#include "util.h" //modified NLIB for my gnu/linux system
#include <iostream>
#include <string>

using namespace std;

void pause(string s);
int main()
{
pause("end test0");
return 0;
}

//---func definitions----
void pause(string s)
{
char c;
cout << s; cin >> c;
}

//---END CODE-----------

//---COMPILER OUTPUT----
cd /home/bturnip/cs417/mod2/
make -k
g++ -g -o nlibtest nlibtest0.cpp
nlibtest0.cpp:9: `string' was not declared in this scope
nlibtest0.cpp:9: parse error before `)' token
nlibtest0.cpp:18: `string' was not declared in this scope
nlibtest0.cpp:18: parse error before `)' token
nlibtest0.cpp: In function `void pause(...)':
nlibtest0.cpp:21: `s' undeclared (first use this function)
nlibtest0.cpp:21: (Each undeclared identifier is reported only once
for each function it appears in.)
make: *** [nlibtest] Error 1

Compilation exited abnormally with code 2 at Thu Aug 14 22:35:40
//---END COMPILER OUTPUT-

 
Reply With Quote
 
 
 
 
Artie Gold
Guest
Posts: n/a
 
      08-15-2003
Danny Anderson wrote:
> Hola!
>
> I am working on a program where I am including a library that came with my
> numerical methods textbook. The "util.h" simply includes a large number
> of files. I had to change the util.h slightly to adjust path names and
> also take into account I am working with a case-sensitive OS.


Just a SWAG, but I would suspect that something is amiss with the
"util.h" header - an unmatched paren or brace perhaps?

<somewhat OT>
Run the header through `indent' and see if there's anything "screwy".
</OT>

>
> My program is below. The sticky point is that adding (#include "util.h")
> seems to negate the (#include <string>) statement somehow. How can I get
> around this? For obvious size reasons, I don't include the util.h
> library, etc. I did include the compiler error messages below.
>
> As always, thanks!
> Danny
>
>
> //---START CODE---------
> /*
> * Commenting out the first #include allows for program compilation
> * on my Redhat9.0 box using g++ 3.2.2.
> *
> */
>
> #include "util.h" //modified NLIB for my gnu/linux system
> #include <iostream>
> #include <string>
>
> using namespace std;
>
> void pause(string s);
> int main()
> {
> pause("end test0");
> return 0;
> }
>
> //---func definitions----
> void pause(string s)
> {
> char c;
> cout << s; cin >> c;
> }
>
> //---END CODE-----------
>
> //---COMPILER OUTPUT----
> cd /home/bturnip/cs417/mod2/
> make -k
> g++ -g -o nlibtest nlibtest0.cpp
> nlibtest0.cpp:9: `string' was not declared in this scope
> nlibtest0.cpp:9: parse error before `)' token
> nlibtest0.cpp:18: `string' was not declared in this scope
> nlibtest0.cpp:18: parse error before `)' token
> nlibtest0.cpp: In function `void pause(...)':
> nlibtest0.cpp:21: `s' undeclared (first use this function)
> nlibtest0.cpp:21: (Each undeclared identifier is reported only once
> for each function it appears in.)
> make: *** [nlibtest] Error 1
>
> Compilation exited abnormally with code 2 at Thu Aug 14 22:35:40
> //---END COMPILER OUTPUT-
>


HTH,
--ag

--
Artie Gold -- Austin, Texas

 
Reply With Quote
 
 
 
 
Stewart Gordon
Guest
Posts: n/a
 
      08-15-2003
Danny Anderson wrote:
> Hola!
>
> I am working on a program where I am including a library that came with my
> numerical methods textbook. The "util.h" simply includes a large number
> of files. I had to change the util.h slightly to adjust path names and
> also take into account I am working with a case-sensitive OS.


Is util.h anywhere near small enough to post here? Maybe you miscopied
it or made a silly mistake when altering it - perhaps showing us your
changes would help.

> My program is below. The sticky point is that adding (#include "util.h")
> seems to negate the (#include <string>) statement somehow. How can I get
> around this? For obvious size reasons, I don't include the util.h
> library, etc. I did include the compiler error messages below.

<snip>

Sounds as if there's an error in your util.h, such as a missing closing
brace or semicolon. Sometimes these things lead to errors being picked
up at points far from the location of the real problem.

And does the same happen if you include util.h _after_ the standard
library includes?

Stewart.

--
My e-mail is valid but not my primary mailbox. Please keep replies on
on the 'group where everyone may benefit.

 
Reply With Quote
 
Danny Anderson
Guest
Posts: n/a
 
      08-15-2003
On Thu, 14 Aug 2003 22:56:19 -0400, Danny Anderson wrote:

> Hola!
>
> I am working on a program where I am including a library that came with my
> numerical methods textbook. The "util.h" simply includes a large number
> of files. I had to change the util.h slightly to adjust path names and
> also take into account I am working with a case-sensitive OS.
>
> My program is below. The sticky point is that adding (#include "util.h")
> seems to negate the (#include <string>) statement somehow. How can I get
> around this? For obvious size reasons, I don't include the util.h
> library, etc. I did include the compiler error messages below.
>
> As always, thanks!
> Danny
>

I nosed through the files that util.h includes. It turns out that (util.h)
includes (Nlib.h) which includes all of the following:

* ------------------------------------------------------------------- */
/* Function prototypes: ANSI C library */
/* ------------------------------------------------------------------- */

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <float.h>
#include <ctype.h>


I am thinking that this is the cause of my problem. Can I safely rename
<string.h> to <cstring> and carry on?
 
Reply With Quote
 
Peter Koch Larsen
Guest
Posts: n/a
 
      08-15-2003

"Danny Anderson" <(E-Mail Removed)> skrev i en meddelelse
news(E-Mail Removed)...
> On Thu, 14 Aug 2003 22:56:19 -0400, Danny Anderson wrote:
>
> > Hola!
> >
> > I am working on a program where I am including a library that came with

my
> > numerical methods textbook. The "util.h" simply includes a large number
> > of files. I had to change the util.h slightly to adjust path names and
> > also take into account I am working with a case-sensitive OS.
> >
> > My program is below. The sticky point is that adding (#include

"util.h")
> > seems to negate the (#include <string>) statement somehow. How can I

get
> > around this? For obvious size reasons, I don't include the util.h
> > library, etc. I did include the compiler error messages below.
> >
> > As always, thanks!
> > Danny
> >

> I nosed through the files that util.h includes. It turns out that

(util.h)
> includes (Nlib.h) which includes all of the following:
>
> * ------------------------------------------------------------------- */
> /* Function prototypes: ANSI C library */
> /* ------------------------------------------------------------------- */
>
> #include <math.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <time.h>
> #include <float.h>
> #include <ctype.h>
>
>
> I am thinking that this is the cause of my problem. Can I safely rename
> <string.h> to <cstring> and carry on?


No - the proper rename is to <string>, not <cstring>. And while it should be
safe, you are probably going to correct a lot of code - replacing string
with std::string. Sp far as I'm aware, there should not be any nasty
surprises here, though.

Kind regards
Peter


 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      08-15-2003
"Peter Koch Larsen" <(E-Mail Removed)> wrote...
>
> "Danny Anderson" <(E-Mail Removed)> skrev i en meddelelse
> news(E-Mail Removed)...
> > On Thu, 14 Aug 2003 22:56:19 -0400, Danny Anderson wrote:
> >
> > > Hola!
> > >
> > > I am working on a program where I am including a library that came

with
> my
> > > numerical methods textbook. The "util.h" simply includes a large

number
> > > of files. I had to change the util.h slightly to adjust path names

and
> > > also take into account I am working with a case-sensitive OS.
> > >
> > > My program is below. The sticky point is that adding (#include

> "util.h")
> > > seems to negate the (#include <string>) statement somehow. How can I

> get
> > > around this? For obvious size reasons, I don't include the util.h
> > > library, etc. I did include the compiler error messages below.
> > >
> > > As always, thanks!
> > > Danny
> > >

> > I nosed through the files that util.h includes. It turns out that

> (util.h)
> > includes (Nlib.h) which includes all of the following:
> >
> > * ------------------------------------------------------------------- */
> > /* Function prototypes: ANSI C library */
> > /* -------------------------------------------------------------------

*/
> >
> > #include <math.h>
> > #include <stdio.h>
> > #include <stdlib.h>
> > #include <string.h>
> > #include <time.h>
> > #include <float.h>
> > #include <ctype.h>
> >
> >
> > I am thinking that this is the cause of my problem. Can I safely rename
> > <string.h> to <cstring> and carry on?

>
> No - the proper rename is to <string>, not <cstring>.


Peter,

<string.h> and <string> are two different headers.

Danny,

You should probably get into a habit of _always_ use new headers:
<cmath>, <cstdio>, <cstdlib>, <cstring>, <ctime>, <cfloat>, <cctype>
in your case.

> And while it should be
> safe, you are probably going to correct a lot of code - replacing string
> with std::string. Sp far as I'm aware, there should not be any nasty
> surprises here, though.


Why does this feel like Deja Vu? Haven't we already discussed this
a couple months back?... Weird.

Anyway, Peter is correct, changing <string.h> to <cstring> will not
really do anything, most likely. If you have "using namespace std;"
in your C++ code, the names will be declared in the global namespace
just as well as if you included the original, C, headers (with .h).

Victor


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Use of Photshop negates reality Jack Digital Photography 28 12-23-2005 06:01 AM



Advertisments