473,416 Members | 1,858 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,416 software developers and data experts.

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

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-

Jul 19 '05 #1
5 6072
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

Jul 19 '05 #2
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.

Jul 19 '05 #3
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?
Jul 19 '05 #4

"Danny Anderson" <bt*****@i.hate.spam> skrev i en meddelelse
news:pa****************************@i.hate.spam...
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
Jul 19 '05 #5
"Peter Koch Larsen" <pk*@mailme.dk> wrote...

"Danny Anderson" <bt*****@i.hate.spam> skrev i en meddelelse
news:pa****************************@i.hate.spam...
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
Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Gregory | last post by:
Hello, I'm trying to do the above in order to process an image and return the result to an html image control. It fails and my key suspects are either the variable that I'm passing in -...
14
by: Dylan Nicholson | last post by:
Been playing around with this all day, and haven't found a solution I like yet. Assuming some initial function: void foo(std::string& src) { src += "some fixed string"; src += bar(); src...
37
by: Zombie | last post by:
Hi, what is the correct way of converting contents of a <string> to lowercase? There are no methods of <string> class to do this so I fallback on strlwr(). But the c_str() method returns a const...
13
by: Steve Edwards | last post by:
Hi, Given a map: typedef map<long, string, greater<long> > mapOfFreq; Is there a quicker way to find the rank (i.e. index) of the elememt that has the long value of x? At the moment I'm...
11
by: Joseph S. | last post by:
Hi all, how do I avoid typing the keyword "$this->" every time I need to reference a member of a class inside the class? (coming from a world of cozy auto-complete enabled Java / .Net IDEs I...
9
by: | last post by:
Is there any sample about getting the results from executing an exe using C#? Thanks for answering.
5
by: Kyle Hayes | last post by:
Is there a way to use the 'r' in front of a variable instead of directly in front of a string? Or do I need to use a function to get all of the slashes automatically fixed? /thanks -Kyle
42
by: barcaroller | last post by:
In the boost::program_options tutorial, the author included the following code: cout << "Input files are: " << vm.as< vector<string() << "\n"; Basically, he is trying to print a vector...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.