aaron.yang 发表于 2020-10-13 21:26:17

string库问题

为啥我我输入下面代码,会提示以下错误:

代码:
#include"strsafe.h"
#include<windows.h>
#include<iostream>
#include<string>
using namespace std;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    int res;
    int count = 0;
    TCHAR pszDest;
    size_t cchDest = 30;
    LPCTSTR pszFormat = TEXT("你总共点击了 %f 次");
    while (true)
    {
      res = MessageBox(NULL, TEXT("test window"), TEXT("是否关闭?"), MB_YESNO | MB_ICONINFORMATION);
      if (res == IDYES)
            count++;
      else
            break;
    }
    LPCWSTR out = TEXT("你总共点击了" + to_string(count) + "次");
    MessageBox(NULL, TEXT("end"), out, MB_OK | MB_ICONINFORMATION);
    return 0;
}

错误信息:

没有与这些操作数匹配的 "+" 运算符
操作数类型为:const wchar_t + std::string

string库不是有"+"操作符吗?

永恒的蓝色梦想 发表于 2020-10-13 21:52:41

宽字符数组加字符串,,,难道不应该是宽字符串吗

永恒的蓝色梦想 发表于 2020-10-13 21:56:06

#include"strsafe.h"
#include<windows.h>
#include<iostream>
#include<string>
using namespace std;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    int res;
    int count = 0;
    TCHAR pszDest;
    size_t cchDest = 30;
    LPCTSTR pszFormat = TEXT("你总共点击了 %f 次");
    while (true)
    {
      res = MessageBox(NULL, TEXT("test window"), TEXT("是否关闭?"), MB_YESNO | MB_ICONINFORMATION);
      if (res == IDYES)
            count++;
      else
            break;
    }
    LPCWSTR out = (L"你总共点击了" + to_wstring(count) + L"次").c_str();
    MessageBox(NULL, TEXT("end"), out, MB_OK | MB_ICONINFORMATION);
    return 0;
}
页: [1]
查看完整版本: string库问题