Roozbeh G
Roozbeh G

Reputation: 557

wstringstream to LPCWSTR

There is an open source code I am using and they created a new string class that they can have syntax's like :

   OpenEvent(EVENT_ALL_ACCESS, FALSE, String() << L"SOMETEXT" << UINT(123));

I was wondering if I can make a same thing conciseness with wstringstream or similar.

OpenEvent is Window API function that 3rd argument is LPCWSTR so you can call it like

  OpenEvent(EVENT_ALL_ACCESS, FALSE, L"some text");

Upvotes: 0

Views: 396

Answers (1)

Benilda Key
Benilda Key

Reputation: 3094

Assuming you have a wstringstream variable named wss, calling "wss.str().c_str()" will do the trick.

This relies on the str member of the basic_stringstream class and the c_str member of the basic_string class. Calling str on a basic_stringstream object obtains the string representation of that object and calling c_str on a basic_string object obtains the C-style string representation of that object.

Upvotes: 5

Related Questions