JustBlossom
JustBlossom

Reputation: 1329

Memory leak issue with printing wchar_t to console?

In a c++ program, I have a pointer to a wchar_t value. In order to get the value at the adress the pointer is pointing to I am doing the following:

std::wstring myAnimalID;
wchart_t* ptr;
ptr = animal->second ->animalID //pointer from a previously defined instance
 myAnimalID =*ptr

However, when I print, it only prints the first value of the wchar.

What am I doing wrong to where I can't print the entire value? I tried specifying the size of the myAnimalID wchar_t value, but I got an access violation error.

I know similar questions have been asked, but I didn't want to ask questions on old threads.

Thanks for any advice.

Upvotes: 0

Views: 185

Answers (1)

Marius Bancila
Marius Bancila

Reputation: 16338

When you say *ptr you dereference the pointer and access the first element of it. If animalID is a wchart_t* then just assigning that to myAnimalID should be enough.

std::wstring myAnimalID = animal->second ->animalID;

Upvotes: 3

Related Questions