Hi everyone I have the following line:
string* playerInfo = "Name: " + firstName + " " + lastName + "\n" +
"Number: " + playerNumber + "\n" +
"Points: " + pointTotal + "\n";
where firstName, lastName, playernumber, pointTotal are all string pointers.
How can I put them all together into another string pointer? The compiler complains about my line of code.
Sorry, I’m not good with C++ I come from a Java background.
Use less pointers. That would have worked if all your variables were just strings. But since you say you have pointers:
One of the first habits you should break when moving from Java to C++ is creating all your objects with
new. In C++,newis not for creating objects, it’s for memory allocation. Any time you can use a local variable instead of dynamic allocation, you should. And when you can’t, try to let some library-provided object likestd::vectortake care of the allocation and deallocation for you.