i’m trying to port code that compiles ok with visual studio and on linux gcc4.6 throws this:
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*’
this is the relevant part of .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;
this is the line 110 of the code:
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();
}
all hints and help appreciated!
The C++ standard library doesn’t define an
open()function for file streams taking the file name as wide characters, independent on whether the stream is for wide characters or not. That is, if you have a wide character string you want to use as a file name you need to convert it to a suitable sequence ofchars. How to do this in the desired way depends on your needs.From the looks of it, Windows implements a method to open files using wide character strings and their standard C++ library supports an extension allowing you to call
open()(or the constructor of a file stream which just callsopen()) using a wide character string.