0

编译 snippets.cpp 时出现以下错误消息。当调用 LoadFile 时会发生这种情况。我正在使用 simpleIni4.2

>     1>------ Build started: Project: SimpleIni, Configuration: Debug Unicode Win32 ------
>     1>Build started 2013-05-24 08:48:37.
>     1>ClCompile:
>     1>  snippets.cpp
>     1>c:\documents\simpleini-4.22\simpleini\snippets.cpp(48): error C2664: 'CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::GetAllKeys'
> : cannot convert parameter 1 from 'const char [13]' to 'const wchar_t
> *'
>     1>          with
>     1>          [
>     1>              SI_CHAR=wchar_t,
>     1>              SI_STRLESS=SI_GenericCase<wchar_t>,
>     1>              SI_CONVERTER=SI_ConvertW<wchar_t>
>     1>          ]
>     1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
>     1>c:\documents\simpleini-4.22\simpleini\snippets.cpp(54): error C2664: 'CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::GetValue' :
> cannot convert parameter 1 from 'const char [13]' to 'const wchar_t *'
>     1>          with
>     1>          [
>     1>              SI_CHAR=wchar_t,
>     1>              SI_STRLESS=SI_GenericCase<wchar_t>,
>     1>              SI_CONVERTER=SI_ConvertW<wchar_t>
>     1>          ]
>     1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
>     1>c:\documents\simpleini-4.22\simpleini\snippets.cpp(61): error C2664: 'CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::GetValue' :
> cannot convert parameter 1 from 'const char [13]' to 'const wchar_t *'
>     1>          with
>     1>          [
>     1>              SI_CHAR=wchar_t,
>     1>              SI_STRLESS=SI_GenericCase<wchar_t>,
>     1>              SI_CONVERTER=SI_ConvertW<wchar_t>
>     1>          ]
>     1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
>     1>c:\documents\simpleini-4.22\simpleini\snippets.cpp(65): error C2664:
> 'CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::GetAllValues' :
> cannot convert parameter 1 from 'const char [13]' to 'const wchar_t *'
>     1>          with
>     1>          [
>     1>              SI_CHAR=wchar_t,
>     1>              SI_STRLESS=SI_GenericCase<wchar_t>,
>     1>              SI_CONVERTER=SI_ConvertW<wchar_t>
>     1>          ]
>     1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
>     1>c:\documents\simpleini-4.22\simpleini\snippets.cpp(84): error C2664: 'CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::SetValue' :
> cannot convert parameter 1 from 'const char [12]' to 'const wchar_t *'
>     1>          with
>     1>          [
>     1>              SI_CHAR=wchar_t,
>     1>              SI_STRLESS=SI_GenericCase<wchar_t>,
>     1>              SI_CONVERTER=SI_ConvertW<wchar_t>
>     1>          ]
>     1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
>     1>c:\documents\simpleini-4.22\simpleini\snippets.cpp(91): error C2664: 'CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::SetValue' :
> cannot convert parameter 1 from 'const char [12]' to 'const wchar_t *'
>     1>          with
>     1>          [
>     1>              SI_CHAR=wchar_t,
>     1>              SI_STRLESS=SI_GenericCase<wchar_t>,
>     1>              SI_CONVERTER=SI_ConvertW<wchar_t>
>     1>          ]
>     1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
>     1>c:\documents\simpleini-4.22\simpleini\snippets.cpp(97): error C2664: 'CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::SetValue' :
> cannot convert parameter 1 from 'const char [8]' to 'const wchar_t *'
>     1>          with
>     1>          [
>     1>              SI_CHAR=wchar_t,
>     1>              SI_STRLESS=SI_GenericCase<wchar_t>,
>     1>              SI_CONVERTER=SI_ConvertW<wchar_t>
>     1>          ]
>     1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
>     1>c:\documents\simpleini-4.22\simpleini\snippets.cpp(107): error C2664: 'CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::Delete' :
> cannot convert parameter 1 from 'const char [13]' to 'const wchar_t *'
>     1>          with
>     1>          [
>     1>              SI_CHAR=wchar_t,
>     1>              SI_STRLESS=SI_GenericCase<wchar_t>,
>     1>              SI_CONVERTER=SI_ConvertW<wchar_t>
>     1>          ]
>     1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
>     1>c:\documents\simpleini-4.22\simpleini\snippets.cpp(110): error C2664: 'CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::Delete' :
> cannot convert parameter 1 from 'const char [13]' to 'const wchar_t *'
>     1>          with
>     1>          [
>     1>              SI_CHAR=wchar_t,
>     1>              SI_STRLESS=SI_GenericCase<wchar_t>,
>     1>              SI_CONVERTER=SI_ConvertW<wchar_t>
>     1>          ]
>     1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
>     1>
>     1>Build FAILED.
>     1>
> 
> 1>Time Elapsed 00:00:02.41
> ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
4

1 回答 1

0

从编译器的错误消息来看,当函数需要一个指向宽字符串的指针时,您似乎传递的是一个窄字符串文字。

尝试L在字符串文字之前指定,以便将指向宽字符串文字(即类型为 的对象const wchar_t[])的指针传递给 GetAllKeys()`:

GetAllKeys(L"Whatever\\Your\\Key\\Is");
//       ^

另外,请注意还有更多此错误的实例。具体来说,您应该将上述内容应用于编译器报告错误的所有调用,包括对以下函数的调用:

  • GetAllKeys()
  • GetValue()
  • SetValue()
  • Delete()

以及我无法从您发布的错误消息中推断出的所有其他可能情况。

于 2013-05-24T13:02:31.123 回答