C++<windows.h>库产生弹框报错

问题:
Windows库 弹框函数报错

#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
std::string msgbox(std::string biaoti,std::string neirong,int leixing){
    return MessageBox(GetForegroundWindow(),biaoti,neirong,leixing/*报错行光标位置*/);
}
int main(){
  cout<<msgbox("标题","内容",1);
  return 0;
}

报错内容:

img

biaoti,neirong,改成biaoti.c_str(),neirong.c_str(),

参考改法1:

LPCSTR msgbox(LPCSTR biaoti,LPCSTR neirong,int leixing){
    return MessageBox(GetForegroundWindow(),biaoti,neirong,leixing);
}
int main(){
  cout<<msgbox("标题","内容",1);
  return 0;
}

改法2:


std::string msgbox(std::string biaoti,std::string neirong,int leixing){
    return MessageBox(GetForegroundWindow(),biaoti.c_str(),neirong.c_str(),leixing);
}
int main(){
  cout<<msgbox("标题","内容",1);
  return 0;
}

第4行 前面的std::string 改成 int

biaoti,neirong,string类型改成LPCSTR类型
或者加上强转
(LPCSTR)biaoti.c_str(),(LPCSTR)neirong.c_str()

修改后:

#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int msgbox(std::string biaoti.c_str() , std::string neirong.c_str() , int leixing){
    return MessageBox(GetForegroundWindow(),(LPCSTR)biaoti.c_str(),(LPCSTR)neirong.c_str(),leixing);
}
int main(){
  cout<<msgbox("标题","内容",1);
  return 0;
}

报错:

img