gpt4 book ai didi

c++ - 将 VS 移植到 linux : no matching function for call to

转载 作者:太空狗 更新时间:2023-10-29 20:15:33 26 4
gpt4 key购买 nike

我正在尝试移植在 visual studio 上编译正常的代码,在 linux gcc4.6 上抛出这个:

PieMenu.cpp: In member function ‘void PieMenu::AddButtons()’:
error: no matching function for call to ‘std::basic_ifstream<char>::open(const wchar_t*)’

PieMenu.cpp:110:44: note: candidate is:
/usr/include/c++/4.6/fstream:531:7: note: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char, _Traits = std::char_traits<char>, std::ios_base::openmode = std::_Ios_Openmode]
/usr/include/c++/4.6/fstream:531:7: note: no known conversion for argument 1 from ‘const wchar_t*’ to ‘const char*’

这是 .cpp 的相关部分:

void PieMenu::AddButtons()
{
CString slash = CUtils::Slash();

CString texturePath,namelistPath=m_pluginPath;
#ifndef linux
texturePath = L".." + slash + L".." + slash; // On windows plugin is located two levels below...
namelistPath += texturePath;
#endif
texturePath += L"data" +slash+ m_folderpath + slash + L"textures" + slash;
namelistPath += L"data" +slash+ m_folderpath + slash + m_folderpath + L".txt";


for(int i=0;i<m_buttonCount;i++)
{
CString bPath = texturePath + m_folderpath + CString(i);
m_buttons.push_back(ToolButton());
m_buttons[i].Setup( bPath.GetWideString(), i);
}

string l_str;
ifstream infile;

这是代码的第 110 行:

        infile.open (namelistPath.GetWideString());

int k=0;
while(!infile.eof() && k < m_buttonCount) // To get you all the lines.
{
std::getline(infile,l_str); // Saves the line in STRING.
m_buttons[k].SetName(CString(l_str.data()));
k++;
}
infile.close();
}

感谢所有提示和帮助!

最佳答案

C++ 标准库没有为以文件名作为宽字符的文件流定义open() 函数,这与流是否为宽字符无关。也就是说,如果您想将一个宽字符串用作文件名,则需要将其转换为合适的 char 序列。如何以所需的方式执行此操作取决于您的需要。

从表面上看,Windows 实现了一种使用宽字符串打开文件的方法,并且其标准 C++ 库支持一个扩展,允许您调用 open()(或文件流的构造函数它只是使用宽字符串调用 open())。

关于c++ - 将 VS 移植到 linux : no matching function for call to,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12760867/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com