#### Archived

This topic is now archived and is closed to further replies.

# string.h will not include NO MATTER WHAT

This topic is 5838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i''ve resorted to including every single include file i can think of because no matter what the compiler says strlen, strcpy, and strcat are undefined identifiers. i''ve included string.h, stdio.h, iostream, iostream.h, stdlib, and many many many more. but it still just says those three are undefined! what is going on?!

##### Share on other sites
#include <string>
#include <iostream>
using namespace std

int main()
{
string strName = "SomeGuy";
cout << strName << endl;
}

this should work...

##### Share on other sites
1) Are you getting a compiler error or a linker error ?

2) What is the EXACT error message the compiler is giving you - "it says there are undeclared identifiers" doesn''t tell us enough to give any exact help.

3) Which compiler?, MSVC?, DevC?, GCC?, ProDG?, CodeWarrior?, Lattice?, Easy?, Watcom?, etc...?, which version?

4) Post some code - maybe something in an earlier header, or an incorrect pragma in your code or a bad define etc is causing those to not actually be included.

5) If the error is actually a linker error, check that you haven''t been playing with the linker options and done something like Ignore All Default Libraries or changed the version of the CRT in use.

6) Are you using anything like MiniCRT (i.e. trying to make a tiny .exe and so changing the default compile behaviours)

7) Have you recently installed a new version of the Platform SDK ? - make sure its environment variables have been set up and its entries are in the Tools->Options->Directories list (assuming MSVC...)

8) Check the Tools->Options->Directories anyway to make sure there are entries in there for lib files.

I reckon it''s probably something wrong near the top of your source code file unless you''ve been fiddling with compiler options.

500x3

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

##### Share on other sites
If you mean the C string header, and you''re using a C++ compiler, you''ll need to
#include <cstringusing namespace std;

The C++ spec requires that these C headers be made available in the std namespace with a c prefix and no .h suffix. Most compilers also let you use string.h, stdlib.h, etc., but don''t count on it.

Don''t listen to me. I''ve had too much coffee.

##### Share on other sites
error C2065: 'strlen' : undeclared identifier
error C2065: 'strcpy' : undeclared identifier
error C2065: 'strcat' : undeclared identifier

i got really annoyed so i went and just found a string class and copied it into C++, including all the headers. i get the same thing on this:

i copied that program, the fixed one down below, directly into my program, which is MSVC 6. i get it on that program also

its a borland program, but the string.h is a standard header i thought?

[edited by - billybob on December 24, 2002 5:52:00 PM]

##### Share on other sites
2 possibilities:

1. you are including the C++ version and not using the std:: namespace identifier (unlikely). I personally would try including "cstring" and adding a line "using namespace std;"

2. your compiler paths are screwed up, and it cannot find the correct file. IF you have added any paths to your comipler, make sure there is not some crappy file named "string" "string.h" "cstring" or "cstring.h" in them ... because you want the built in libraries ...

##### Share on other sites
Or possibility 3, something is misconfigured with your MSVC installation.

Or possibility 4, something up with your precompiled headers (e.g. you''re including a stdafx.h somewhere and the required headers aren''t in it).

I just visited that site and the code builds fine for me with MSVC (with the November 2001 Platform SDK, but that won''t matter). What I did:

1) Open DevStudio
2) Select New->Projects and choose Win32 Console Application
3) Set a name and path
4) Select "An empty project" from the "what kind of console application" dialog.
5) Finish, Ok
6) File->New...->C++ Source File - blah.cpp
7) Copy code from that site into blah.cpp (no other contents in file)
8) remove the condefs.h #include since that file doesn''t exist in MSVC
9) Hit F7 to build -:
Compiling...blah.cppe:\projects\experiments\moo\blah.cpp(73) : warning C4068: unknown pragmaLinking...moo.exe - 0 error(s), 1 warning(s)

The unknown pragma is simply complaining about the Borland argsused, it''s only used in that code to prevent a warning on Borland compilers.

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

##### Share on other sites
thats exactly what i did, and i checked the paths, they are all there. i''m going to reinstall

##### Share on other sites
I recently had a problem with wanting to use getch() within a C++ program, where didn''t have it. What I had to do was include the original file (where getch() is defined), but put ''extern "C" {'' around it for it to fit in, like so:
extern "C" {#include <conio.h>}

and then the rest of my headers, and so forth. It worked fine. Perhaps you''d like to do that?

Twilight Dragon

##### Share on other sites
check the header file, maybe it''s corrupt?

1. 1
2. 2
Rutin
20
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633760
• Total Posts
3013722
×