0

I want to have array of pointers to strings.

std::string *part [n];

I also have object witch has method that return string,

let's name it:

object1.getText();

when I want to get part of the string to array's element it's not a problem:

std::string h = object1.getText().substr(0,5) 
array[0] = &h;

but how can I append some text to existing element?

something I've tried:

std::string hh = object1.getText().substr(6) 
array[0].append(&hh);

didn't work.

3
  • Future bug: array[0] = &object1.getText().substr(0,5); the string returned by substr does not last long enough for a pointer to it to be meaningful. Commented Oct 20, 2019 at 17:25
  • 1
    std::string::append has no overload that accepts a pointer to a string. array[0].append(...) should be array[0]->append(...) because array [0] is a pointer. I recommend going over the section on pointer syntax in your text book again and working through some of the examples. Commented Oct 20, 2019 at 17:28
  • okey, my fault it's clear now, thank @user4581301 Commented Oct 20, 2019 at 17:39

1 Answer 1

1

thank to @user4581301 , the solution is

std::string *part [n];

std::string h = object1.getText().substr(0,5) 
array[0] = &h;

std::string hh = object1.getText().substr(6);
array[0]->append(hh);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.