C++ headers

K

kramer31

Hi. I'm trying to use the STL string class (new to STL), but not
having much luck. FYI, I'm using g++ on Linux 2.6. I included the
header as instructed:

#include <string>

But I get the error message:

error: `string' does not name a type

I looked at my '/usr/include' directory and found no file called
'string'. The file 'string.h' of course points to the basic string
functions.

Am I missing the STL headers?

If so why didn't the compiler yell at me that it couldn't find the
file?

Or did I jsut do something stupid?

Thanks in advance, guys.
 
R

Robert Bauck Hamar

kramer31 said:
Hi. I'm trying to use the STL string class (new to STL), but not
having much luck. FYI, I'm using g++ on Linux 2.6. I included the
header as instructed:

#include <string>

But I get the error message:

error: `string' does not name a type

I looked at my '/usr/include' directory and found no file called
'string'. The file 'string.h' of course points to the basic string
functions.

What about /usr/include/c++/*/ ?
Am I missing the STL headers?

Probably not. In any case, the standard headers don't need to be actual
files.
If so why didn't the compiler yell at me that it couldn't find the
file?

It did find the file. Else it would have said something like 'string: No
such file or directory'.
Or did I jsut do something stupid?

My guess is that you used only 'string' instead of 'std::string' in your
code, but it's hard to say without any code.
 
K

kramer31

What about /usr/include/c++/*/ ?

Non-existent.
Probably not. In any case, the standard headers don't need to be actual
files.

My guess is that you used only 'string' instead of 'std::string' in your
code, but it's hard to say without any code.

You are correct, sir! I did.

Still, I wouldn't mind finding out where that header is... (I guess
I'm just curious). I'm more used to c style headers where the actual
name of the file is in the #include directive. How do the
preprocessor know how to find <string>?

Anyway, thanks for your help.
 
R

Roberto Waltman

kramer31 said:
Hi. I'm trying to use the STL string class (new to STL), but not
having much luck. FYI, I'm using g++ on Linux 2.6. I included the
header as instructed:

#include <string>

But I get the error message:

error: `string' does not name a type
...

Try:

#include <string>
...
std::string some_string;

or

#include <string>
...
using namespace std;
...
string some_string;


Roberto Waltman

[ Please reply to the group,
return address is invalid ]
 
J

Juha Nieminen

kramer31 said:
Still, I wouldn't mind finding out where that header is... (I guess
I'm just curious). I'm more used to c style headers where the actual
name of the file is in the #include directive. How do the
preprocessor know how to find <string>?

I assume the C++ standard, once again, doesn't specify exactly
how to do it, but in practice there is a file named "string" in the
include search path of the compiler. Filename extensions are not
mandatory in any filesystem.
 
T

tom

You are correct, sir! I did.

Still, I wouldn't mind finding out where that header is... (I guess
I'm just curious). I'm more used to c style headers where the actual
name of the file is in the #include directive. How do the
preprocessor know how to find <string>?

Anyway, thanks for your help.

why don't you search the file by name, and verify whether the path is
in the search path of your compiler
 
K

kramer31

why don't you search the file by name, and verify whether the path is
in the search path of your compiler

Actually, I did that ... well, I'm not sure what the search path of g+
+ is, but I searched /usr/include and there is no file called
'string'. There are lots of files like 'string.h' 'strings.h', but no
'string'.

A similar problem has come up as I'm trying to use the class hash_map
with #include <ext/hash_map>. The compiler finds its header, but I
can't.
 
B

BobR

kramer31 said:
Actually, I did that ... well, I'm not sure what the search path of g+
+ is, but I searched /usr/include and there is no file called
'string'. There are lots of files like 'string.h' 'strings.h', but no
'string'.

Then search from '/' (root).

If you don't find it, you may need to install another 'g++' package.
 
O

Owen Jacobson

Actually, I did that ... well, I'm not sure what the search path of g+
+ is, but I searched /usr/include and there is no file called
'string'. There are lots of files like 'string.h' 'strings.h', but no
'string'.

A similar problem has come up as I'm trying to use the class hash_map
with #include <ext/hash_map>. The compiler finds its header, but I
can't.

In the future, you might want to consider a GCC or linux group, rather
than a C++ language group, for compiler-specific questions.

That said, on my linux system the file "string" and "deque" and all
the other standard includes exist in /usr/include/c++/4.1.2/ and were
provided by the package libstdc++6. The same files may or may not be
in the same place on your system.
 
O

Old Wolf

Actually, I did that ... well, I'm not sure what the search path of g+
+ is, but I searched /usr/include and there is no file called
'string'. There are lots of files like 'string.h' 'strings.h', but no
'string'.

A similar problem has come up as I'm trying to use the class hash_map
with #include <ext/hash_map>. The compiler finds its header, but I
can't.

For best answers, ask in a g++ newsgroup. On my
system the C++ standard headers (note, the term
'STL' refers to a pre-standard library) are in
/usr/include/g++-3/
 
J

Jorgen Grahn

Actually, I did that ... well, I'm not sure what the search path of g+
+ is, but I searched /usr/include and there is no file called
'string'. There are lots of files like 'string.h' 'strings.h', but no
'string'.

Since you're on Unix, the find(1) command is your friend.

salix:~% find /usr/include -name string
/usr/include/c++/4.1.2/debug/string
/usr/include/c++/4.1.2/string

And I'm fairly sure GCC documents its search path, and/or they way to
ask the compiler what it is.

/Jorgen
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top