I try copy a string to another string, but it has error with "_ps->copy(_pt,_beg,_end);".
This is my code( but it is not full code):

        string* find_The_Longest_Word(string* _ps, int _beg, int_end)
            string* _pt;
            _pt =new string();
            return _pt;
4 Years
Discussion Span
Last Post by Dang_1

Looking at this code, it seems that _ps is a pointer to a string object.

So this:

_ps->copy is an attempt to use the string class function named copy.

Here is the prototype of that function.
size_t copy (char* s, size_t len, size_t pos = 0) const;

So the first parameter has to be a char-pointer. You're trying to use _pt, which is a string-pointer. A char-pointer and a string-pointer are different things. The function expects a char-pointer, you're trying to use a string-pointer.

What are you actually trying to do here? You've got a string; are you trying to make an exact copy of that string, or are you trying to copy only some of the letters of that string? There are much better ways to do this than for you to use the copy function (and why are you creating that string on the heap, with new? - if you don't have a good reason to do that, you're just making things much harder for yourself)

Edited by Moschops


thanks, I just want copy some of the letters of the string?
This is my ex:
Give you a string, find the longest word and print it with lenght of word.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.