C++ headers

Discussion in 'C++' started by kramer31, Jul 28, 2007.

  1. kramer31

    kramer31 Guest

    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.
    kramer31, Jul 28, 2007
    #1
    1. Advertising

  2. kramer31 wrote:

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

    --
    rbh
    Robert Bauck Hamar, Jul 28, 2007
    #2
    1. Advertising

  3. kramer31

    kramer31 Guest

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

    Non-existent.

    >
    > > Am I missing the STL headers?

    >
    > 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.
    kramer31, Jul 28, 2007
    #3
  4. kramer31 wrote:

    >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 ]
    Roberto Waltman, Jul 28, 2007
    #4
  5. kramer31 wrote:
    > 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.
    Juha Nieminen, Jul 29, 2007
    #5
  6. kramer31

    tom Guest

    On Jul 29, 5:37 am, kramer31 <> wrote:
    > > What about /usr/include/c++/*/ ?

    >
    > Non-existent.
    >
    >
    >
    > > > Am I missing the STL headers?

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


    why don't you search the file by name, and verify whether the path is
    in the search path of your compiler
    tom, Jul 29, 2007
    #6
  7. kramer31

    param Guest

    Try

    #include <bstring.h>

    Thanks
    param, Jul 29, 2007
    #7
  8. kramer31

    kramer31 Guest

    > 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.
    kramer31, Jul 29, 2007
    #8
  9. kramer31

    BobR Guest

    kramer31 <> wrote in message...
    > > 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'.


    Then search from '/' (root).

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

    --
    Bob R
    POVrookie
    BobR, Jul 29, 2007
    #9
  10. On Jul 29, 11:58 am, kramer31 <> wrote:
    > > 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.


    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.
    Owen Jacobson, Jul 30, 2007
    #10
  11. kramer31

    Old Wolf Guest

    On Jul 30, 6:58 am, kramer31 <> wrote:
    > 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/
    Old Wolf, Jul 30, 2007
    #11
  12. kramer31

    Jorgen Grahn Guest

    On Sun, 29 Jul 2007 18:58:07 -0000, kramer31 <> wrote:
    >> 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'.


    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

    --
    // Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
    \X/ snipabacken.dyndns.org> R'lyeh wgah'nagl fhtagn!
    Jorgen Grahn, Aug 2, 2007
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Douglas Gage

    Datagrid Headers???

    Douglas Gage, Jan 15, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    480
    Douglas Gage
    Jan 15, 2004
  2. nomadx
    Replies:
    1
    Views:
    480
    dinser
    Sep 19, 2003
  3. dont bother
    Replies:
    0
    Views:
    773
    dont bother
    Mar 3, 2004
  4. Phil
    Replies:
    4
    Views:
    663
    Gabriel Genellina
    Jan 17, 2010
  5. Ian
    Replies:
    2
    Views:
    1,914
Loading...

Share This Page