views:

469

answers:

2

When i'm trying to declare a function with a string parameter in .h file an error occurs. I haven't forgot to include string.h =) Everything builds fine when i'm using char[], but the i want the argument to be a string.

+5  A: 

string.h doesn't exist in C++. Did you mean string (without the .h)? Additionally, the string class resides in the std namespace you need to qualify the type usage:

std::string timeToStr(std::string);

It would be helpful if you had posted the exact error message and a code to reproduce the error.

Konrad Rudolph
hehehe ... great minds ;)
Goz
thanks a lot, i mentioned <code>using namespace std;</code> in my cpp file, but forgot about <code>std::</code> the header.
mknight
`<string.h> does exist in c++, since it is inherited from c ;). However, it has nothing to do with `<string>`
Evan Teran
@Evan: yes but `<string.h>` exists only for reasons of backwards compatibility, it should not be used. Use the header `<cstring>` instead, it replaces `<string.h>`.
Konrad Rudolph
+1  A: 

try

#include <string>

instead of

#include <string.h>

they are different things - string.h is the CRT, string is the STL.

gbjbaanb