string.h will not include NO MATTER WHAT

Started by
9 comments, last by billybob 21 years, 3 months ago
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?!
Advertisement
#include <string>
#include <iostream>
using namespace std

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



this should work...
Friðrik Ásmundsson
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

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

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

http://www.decompile.com/html/invalid_pointer_addition.html

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

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

thats exactly what i did, and i checked the paths, they are all there. i''m going to reinstall
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
{[JohnE, Chief Architect and Senior Programmer, Twilight Dragon Media{[+++{GCC/MinGW}+++{Code::Blocks IDE}+++{wxWidgets Cross-Platform Native UI Framework}+++
check the header file, maybe it''s corrupt?

This topic is closed to new replies.

Advertisement