简体   繁体   English

无法将参数1从'CHAR [260]'转换为'const std :: basic_string <_Elem,_Traits,_Ax>

[英]cannot convert parameter 1 from 'CHAR [260]' to 'const std::basic_string<_Elem,_Traits,_Ax>

Hi when i compile my code i have that error my problem on 2 lines that included : if ( !processName.compare(processInfo.szExeFile) ) also i use multiply-byte character but i don't know why have same problem? 嗨,当我编译我的代码时,我的错误出现在两行中,包括:if(!processName.compare(processInfo.szExeFile))我也使用多字节字符,但我不知道为什么会有同样的问题?

my error is: 我的错误是:

int std::basic_string<_Elem,_Traits,_Ax>::compare(const std::basic_string<_Elem,_Traits,_Ax> &) const' : 
cannot convert parameter 1 from 'CHAR [260]' to 'const std::basic_string<_Elem,_Traits,_Ax> &'

and my code: 和我的代码:

 #include<fstream>
 #include<sstream>
 #include<string>
 #include<iostream>
 #include<iomanip>
 #include<cstdlib>
 #include<Windows.h>
 #include<TlHelp32.h>

using std::ifstream;
using std::string;
using std::getline;
using std::ios;
using std::cerr;
using std::cout;
using std::endl;
using std::fixed;
using std::left;
using std::right;
using std::showpoint;
using std::cin;

class check {

public :


void check_seta () {

    ifstream cfgm2("fix.cfg",ios::in);

    string cfgLine;

    while (getline(cfgm2,cfgLine)) {

        if (string::npos != cfgLine.find("pn ff")){

             if (cfgLine.at(19) == '0'){

                 MessageBoxW(NULL , L"naananaana",NULL,MB_ICONERROR); 

                 std::wstring Processname(L"lol.exe");

                 DWORD ProcessId = FindProcessId(Processname);

                 HANDLE pHandle = OpenProcess(PROCESS_ALL_ACCESS, TRUE ,ProcessId);

                 TerminateProcess(pHandle,0);

                 CloseHandle(pHandle);
             }
             break;
        }

    }
  }

 DWORD FindProcessId(const std::wstring& processName)
    {
    PROCESSENTRY32 processInfo;
    processInfo.dwSize = sizeof(processInfo);

    HANDLE processesSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
    if ( processesSnapshot == INVALID_HANDLE_VALUE )
    return 0;

    Process32First(processesSnapshot, &processInfo);

    // I have problem in this line

    if ( !processName.compare(processInfo.szExeFile) )
    {
        CloseHandle(processesSnapshot);
        return processInfo.th32ProcessID;
    }

    while ( Process32Next(processesSnapshot, &processInfo) )
    {

    // and I have problem with this line

        if ( !processName.compare(processInfo.szExeFile) )
        {
            CloseHandle(processesSnapshot);
            return processInfo.th32ProcessID;
        }
    }

    CloseHandle(processesSnapshot);
    return 0;
  }
 };

processName is a wstring. processName是一个wstring。 wstring and string are not compatible, nor can wstring be initialized by char *. wstring和string不兼容,也不可用char *初始化wstring。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将参数1从&#39;char&#39;转换为&#39;const std :: basic_string &lt;_Elem,_Traits,_Ax&gt;&&#39; - cannot convert parameter 1 from 'char' to 'const std::basic_string<_Elem,_Traits,_Ax> &' 错误C2664:无法将参数1从&#39;const std :: basic_string &lt;_Elem,_Traits,_Ax&gt;&#39;转换为&#39;std :: wstring& - error C2664: cannot convert parameter 1 from 'const std::basic_string<_Elem,_Traits,_Ax>' to 'std::wstring & 无法从“ TCHAR [260]”转换为“ std :: basic_string” <wchar_t,std::char_traits<wchar_t> ,性病::分配器 <wchar_t> &gt; - Cannot convert from 'TCHAR [260]' to 'std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>> 无法从&#39;const char *&#39;转换为&#39;std :: _ St​​ring_const_iterator &lt;_Elem,_Traits,_Alloc&gt; - cannot convert from 'const char *' to 'std::_String_const_iterator<_Elem,_Traits,_Alloc> C ++类型转换:错误C2440:“正在初始化”:无法从“ HRESULT”转换为“ std :: basic_string &lt;_Elem,_Traits,_Alloc&gt;” - c++ type conversion: error C2440: 'initializing' : cannot convert from 'HRESULT' to 'std::basic_string<_Elem,_Traits,_Alloc>' std::basic_string 作为 function 模板的参数不能从 const char* 推导出来 - std::basic_string as a parameter of a function template cannot be deduced from const char* “ str2Int(std :: basic_string <char, std::char_traits<char> ,std :: allocator <char> &gt; const&)”,引用自: - “str2Int(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)”, referenced from: 无法转换 &#39;std::basic_string<char> &#39; 到 &#39;const char*&#39; 作为参数 &#39;1&#39; 到 &#39;int system(const char*)&#39; - cannot convert 'std::basic_string<char>' to 'const char*' for argument '1' to 'int system(const char*)' 没有合适的构造函数来将“ const char [8]”转换为“ std :: basic_string” <wchar_t, std::char_traits<wchar_t> ,std :: allocator <wchar_t> &gt;” - no suitable constructor exists to convert from “const char [8]” to “std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>>” 1 IntelliSense:没有合适的构造函数可以从“bool”转换为“std :: basic_string” <char, std::char_traits<char> ,std :: allocator <char> &gt;” - 1 IntelliSense: no suitable constructor exists to convert from “bool” to “std::basic_string<char, std::char_traits<char>, std::allocator<char>>”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM