What is wrong with this c++ win32 code?

Vijayadithyan .N 121 Reputation points
2022-11-13T14:53:40.877+00:00

I wrote this code:
259894-image.png

And this error showed up:
259778-image.png

why did it occur & how do I fix it?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,430 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,544 questions
{count} votes

2 answers

Sort by: Most helpful
  1. RLWA32 40,771 Reputation points
    2022-11-13T15:44:39.483+00:00

    From the text of the error message it seems that the error_message variable should be type wstring instead of string.

    0 comments No comments

  2. Junjie Zhu - MSFT 15,366 Reputation points Microsoft Vendor
    2022-11-18T08:50:26.41+00:00

    Hi @Vijayadithyan .N ,
    Welcome to Microsoft Q&A!

    A character literal that begins with the L prefix is a wide-character literal. As @RLWA32 said, you need to use wstring.
    But std:string is a character literal.
    If you want use std:string in your code, you need remove L.

    string message = "123";  
    string error_message = "Error" + message + "\n";  
    

    Thank you,
    Junjie


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments