Hello. I am a new member of this web site. The reason for joining is that when I experienced some problems , I found most solutions on this website. Sadly, I cannot find all answers to my problems.

That's why I am here now and I want to ask you something.

The following code compiles and works. But the output shows
5 + address of "Hello". But I want it to show 5Hello.

I know that .c_str() returns a const char*, that's why I need your help :P So what is the code to show the output 5Hello?

btw, I've also heard something about std::wcout, but that didnt work for me either.

#include <windows.h>
#include <iostream>
#include <string.h>

class CPerson
{
	int *PAge;
	std::wstring *PName;
public:
	CPerson (int, std::wstring);
	int ShowAge();
	std::wstring ShowName();
};

CPerson::CPerson(int AAge, std::wstring AName)
{
	PAge = new int;
	PName = new std::wstring;
	*PAge = AAge;
	*PName = AName;
}

int CPerson::ShowAge()
{
	return *PAge;
}

std::wstring CPerson::ShowName()
{
	return *PName;
}

int main ()
{
	CPerson BPerson(5, TEXT("Hello"));
	std::cout << BPerson.ShowAge() << BPerson.ShowName().c_str();
	Sleep(1000); // I used this to see what the output shows
	return 0;
}

Recommended Answers

All 3 Replies

Shouldn't you be able to use wcout instead of cout to get the disired result?

Havn't tested it, tho'.

Kind regards,

- Henning

This is soooo weird XD When I first tried it I got load of errors. I think I made a mistake back then. That's why I asked the question in the first place.

But indeed, you were right. Thanks for saying though, because otherwise I wouldn't have tried it again. I feel so silly xD (but that is with most mistakes :P)

Thanks for your fast reply ^^

No problem ;) Glad I could help..
remember to set the thread as solved..

Have fun programming :

- Henning

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.