0

we are migrating code to VS 2019 from legacy code

We have an overloaded function on operator '<<' that is invoking basic_ostream function when executing the following lines.

CStringArray asLine;
 
using ostream       = basic_ostream<char, char_traits<char>>;
ostream os;
    os << (LPCTSTR)asLine[nLine2]; <---- this line is producing the  C2280 error with message
"basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const wchar_t*) = delete"

This was working in legacy application. how to overcome this issue?

please suggest any workaround

CStringArray asLine; // class with set and get functions.
ostream os;
int nLine2 = 20; // nline has subscript valve to the asline[]

os << (LPCTSTR)asLine[nLine2];

        
James Z
  • 12,209
  • 10
  • 24
  • 44
Madhu Rao
  • 1
  • 1
  • Guessing this is MFC. Please tag your question properly to get the correct audience for it. – James Z Jan 19 '23 at 09:03
  • 2
    `basic_ostream` – zdf Jan 19 '23 at 09:09
  • 3
    *"This was working in legacy application."* - Nope, it wasn't. The legacy application compiled to different code, which can still be made to work today. What changed is the compiler environment: In the legacy case the `MBCS` and `_MBCS` preprocessor symbols were defined. This changed to having the `UNICODE` and `_UNICODE` preprocessor symbols defined. As far as the compiler is concerned, `TCHAR` changed from `char` to `wchar_t`. – IInspectable Jan 19 '23 at 09:16
  • Don't use here the cast LPCTSTR if you want a char, which is need for ostream. Or you can try to replace ostream with wostream. – Tom Tom Jan 19 '23 at 21:11
  • thanks for your suggestions. the use of wostream in place of ostream helped to solve the issue. – Madhu Rao Jan 21 '23 at 07:29

0 Answers0