我正在尝试移植使用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();
}
所有提示和帮助表示赞赏!
答案 0 :(得分:7)
C ++标准库没有为文件流定义open()
函数,文件名为宽字符,与流是否适用于宽字符无关。也就是说,如果您想要将宽字符串用作文件名,则需要将其转换为char
s的合适序列。如何以理想的方式执行此操作取决于您的需求。
从外观上看,Windows实现了一种使用宽字符串打开文件的方法,它们的标准C ++库支持扩展,允许您调用open()
(或者只调用{{}的文件流的构造函数。 1}})使用宽字符串。