将 GetLine 与 ifstream 一起使用 - "getline" 的实例不匹配参数列表

Using GetLine with ifstream - no instance of "getline" matches the argument list

我正在尝试解决这个问题,但出于某种原因,我不断收到此消息:

no instance of "getline" matches the argument list.

我查过这个问题,很多时候是因为人们使用 ofstream,或者他们不使用 ifstream 对象(如果我说得对的话)的第一个属性是 getline。我迷路了。

        #include <string>

        std::wifstream myfile;
        myfile.open("LaunchLocations.txt");
        getline(myfile, gameLaunchtest.directory);

struct gameLaunch
{
    wchar_t directory[MAX_PATH];
    wchar_t AppName[MAX_PATH];
    wchar_t ComboBoxName[MAX_PATH];

}gameLaunchtest;

std::getline() does not support reading into a wchar_t[] array, only into a std::string or std::wstring (depending on the input stream type). To read into a wchar_t[], you need to use the std::wifstream::getline() 方法改为:

myfile.getline(gameLaunchtest.directory, MAX_PATH);