Archived

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

Dev-C++ & string.h

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m using Dev-C++ 4.18 and I can''t get the string.h or the string libraries to work at all. Has anyone else has this problem and do you know how to fix it???

Share this post


Link to post
Share on other sites
heres what I''m doing:


//------------------------------------------------------------------------------

//This file declares the CStr class.

//Every module that refers to CStr must include

// this file.


class CStr {
char sData[256];
public:
char *get(void);
int getlength(void);
void cpy(char *s);
void cat(char *s);
};



and I get these errors:
gcc: Compilation of header file requested
gcc: file path prefix `C:\PROGRA~1\DEV-C_~1\Bin\'' never used

also:

//------------------------------------------------------------------------------

//This file contains definitions of CStr functions.

//Compile this file and like to the project.


#include "cstr.h"
#include <string>

char* CStr::get(void) { // Return ptr to string data

return sData;
}

int CStr::getlength(void) { // Return length.

return strlen(sData);
}

void CStr::cpy(char *s) { // Copy from string arg.

strcpy(sData, s);
}

void CStr::cat(char *s) { // Concatenate string arg

strcat(sData, s); // onto object.

}


and I get these errors:
C:\PROGRA~1\DEV-C_~1\Lib\\libmingw32.a(main.o)(.text+0x8e): undefined reference to `WinMain@16''

i got this source out of a book so it should work but its not.

Share this post


Link to post
Share on other sites
Make sure your project settings are set to console app if that''s what you wish to create. Oh, having a main function also doesn''t hurt . And you want cstring, seeing as how you''re using the C string library. If you wanted std::string (which you don''t) you''d include string.

Share this post


Link to post
Share on other sites
- The C header for C string (char*) handling is called <string.h>
- In C++, C headers are prefixed with a c and stripped of .h suffix, so in C++ you would #include the above header as <cstring>
- The C++ header <string> has nothing to do with any of the above, as it declares C++''s string type, which, I might add, is generally much more convenient and more robust than C''s raw character arrays.

Share this post


Link to post
Share on other sites
Also remember the string handling functions inside cstring are inside the std namespace. So if you're going to use it remember to qualify it.





--{You fight like a dairy farmer!}

[edited by - Greatwolf on February 21, 2004 3:45:43 AM]

Share this post


Link to post
Share on other sites