Poblems copying a string of text

Started by
4 comments, last by DividedByZero 12 years, 6 months ago
Hi Guys,

I am writing a program that displays entires from an LDAP directory.

But, for the life of me, I can't put the text returned into a simple string variable.
[source]ppValue = ldap_get_values(pLdap,pEntry,pAttribute);

iValue = ldap_count_values(ppValue);
if(iValue)
{
std::cout<<ppValue[0]<<"\t";

//std::strcpy(szPath,ppValue[0]); // This wont compile <<<<<<
}[/source]
So, the std::cout displays happily. But I cant work out how to store this into a string (or char) variable.

error C2664: 'strcpy' : cannot convert parameter 1 from 'std::string' to 'char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

Any help would be greatly appreciated. :cool:

Advertisement
To assign a C string to a std::string object just use the = operator.
You don't need to use strcpy on std::strings. Just use the = operator:

const char* foo = "test";
std::string bar;

bar = foo;
std::cout << bar << std::endl;




[edit] Ninja'd!

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Thanks guys.

I now have this;

iValue = ldap_count_values(ppValue);
if(iValue)
{
std::cout<<ppValue[0]<<"\t";
szPath=ppValue[0];
std::cout<<szPath<<std::endl;
}


But this produces this error;

error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)



Did you #include both <string> and <iostream>?
Have now. Great pickup :cool:

All good now.

This topic is closed to new replies.

Advertisement