String types in library and header file

Hello everybody,

I don't if this is a dumb question but I could find any answers.
How can I compile a library where there are functions that have string as arguments

 
int myfunction(string c,string a);


and of course a header file containg this functions.

thank you,


Billy
Like everything else in the standard library, string is in the std namespace, so you need to write std::string.
Note that if you don't need to change the passed strings in any way, you should pass by constant reference, i.e. const std::string&. If you don't want to keep writing this out every time, you can add a global typedef.
Last edited on
Hi Athar,


I'm sorry but I didn't understand. Could you please explain me a litte bit more??? An example could be great. ;)

Thank you,


Billy
Uh... you just write
int myfunction(std::string c,std::string a);
or rather:
int myfunction(const std::string& c,const std::string& a);

You also need to include <string> in your header.
thank you Athar.
Topic archived. No new replies allowed.