本文介绍了这段代码出了什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我没有C ++知识。我有一个项目的源代码,并添加了这些新行来从ini文件中的Server部分读取IP和PORT值,现在我无法编译它。有人可以帮我弄这个吗?谢谢。



Hello everyone, I have no C++ knowledge. I have the source code of a project and added these new lines to read IP and PORT values from Server section inside a ini file, and now I can't compile it. Can someone help me with this? Thank you.

if (GetFileAttributes(gamepath.c_str()) != INVALID_FILE_ATTRIBUTES)
    {
        char ip[16];
        int port;

        GetPrivateProfileString(L"Server", L"IP", L"127.0.0.1", ip, _countof(ip), gamepath.c_str());
        GetPrivateProfileInt(L"Server", L"PORT", port, gamepath.c_str());
    }







char ip [16];错误:类型char *的参数与LPWSTR类型的参数不兼容




char ip[16]; Error: argument of type "char*" is incompatible with parameter of type "LPWSTR"

推荐答案


char *mychar;
size_t nSize1 = 1 + strlen( mychar );
LPWSTR wUserName = new WCHAR[nSize1];
mbstowcs( wUserName, mychar, nSize1 );
  // use wUserName but after all the usage do remember delete it
delete []wUserName;





看看这个 [对于mbstowcs。



希望这会有所帮助!!



i不知道你的整个代码,这只是命中和试用



Check out this msdn link[^] for mbstowcs.

hope this helps !!

i dont know your whole code, this is all just hit and trial

 char ip[16];
 size_t nSize1 = 1 + strlen( ip );
 LPWSTR wIPName = new WCHAR[nSize1];
 mbstowcs( wIPName, ip, nSize1 );
 //now wIPNmae has the string in required fromat
 GetPrivateProfileString(L"Server", L"IP", L"127.0.0.1", wIPName, _countof(ip),gamepath.c_str());
//the _countof() function is also using 'ip', i hope it does not complain

 //when you are done with wIPNmae then delete it
delete []wIPName;


这篇关于这段代码出了什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-21 01:10